"Andre Engels" <andreeng...@gmail.com> wrote

eval("float(3/2)")

That still does not work, because the 'float' comes after the
division. 3/2 equals 1, so float(3/2) equals 1.0. To make it work,
you'll have to put the float inside the division:

eval("float(3)/2")

Ahem! Quite. That was what I actually intended to post!

But having seen the other posts suggesting using future I had a rethink.

I don't think either float() or the "3.0" approach will help the OP because I suspect he is trying to eval a string stored in a variable. In that case the "import future" trick is probably the only solution that will work, short of parsing the string and doing the division without using eval...

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to