How to calculate a file of equations in python

Boris Borcic bborcic at gmail.com
Wed Mar 21 06:31:06 EDT 2007


r=''
for line in file : r = str(eval(r+line))

John wrote:
> Hi,
> I have a text file which contains math expression, like this
> 134
> +234
> +234
> 
> (i.e. an operation (e.g. '+) and then a number and then a new line).
> 
> Can you please tell me what is the easiest way to calculate that file?
> for example the above example should be = 134 + 234 + 234 = 602.
> 
> Thank you.
> 




More information about the Python-list mailing list