Is there a way to execute an eval-like function that coerces its values to floating point? I am hoping to
eval('1/3')
and have it return the floating point value .333333 rather than the integer value 0.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Grab the compiler flag for
__future__.division, pass it and your code tocompile(), then runeval()on the returned code object.(note by mh) This has the added advantage of not changing the division operation globally, which might have unexpected side effects. (end note)