On Thu, Jan 15, 2009 at 1:14 AM, Mr Gerard Kelly
wrote:
> If you have a string "6", and you do int("6"), you get the number 6.
>
> But if you have a string "2*3" and you do int("2*3") you get a name error.
>
> How do you take an expression in a string, and evaluate the expression
> to get a number
> If you have a string "6", and you do int("6"), you get the number 6.
> But if you have a string "2*3" and you do int("2*3") you get a name error.
the reason you get this error is because "2*3" is not a string
representation of an integer whereas "6" is. in other words 2*3 is not
a number.
> Ho
Try eval("2*3")
On Thu, 2009-01-15 at 10:14 +1000, Mr Gerard Kelly wrote:
> If you have a string "6", and you do int("6"), you get the number 6.
>
> But if you have a string "2*3" and you do int("2*3") you get a name error.
>
> How do you take an expression in a string, and evaluate the expressi
If you have a string "6", and you do int("6"), you get the number 6.
But if you have a string "2*3" and you do int("2*3") you get a name error.
How do you take an expression in a string, and evaluate the expression
to get a number?
I want to be able to turn the string "2*3" into the number 6.
t