[Tutor] eval and floating point
alan.gauld at btinternet.com
Thu Jan 15 19:20:24 CET 2009
"Andre Engels" <andreengels at gmail.com> wrote
> 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:
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...
Author of the Learn to Program web site
More information about the Tutor