Question

D

Dag Hansteen

s = "2+2"Traceback (most recent call last):
File "<pyshell#64>", line 1, in ?
answer = int(str(s))
ValueError: invalid literal for int(): 2+2

How do I this ? I have a string with a such expression and I want to return the answer in a variable.

Regards Dag Hansteen

(PS: sorry if I double post, dont know if I sent the other)
 
T

Thomas =?ISO-8859-1?Q?Kr=FCger?=

Dag said:
Traceback (most recent call last):
File "<pyshell#64>", line 1, in ?
answer = int(str(s))
ValueError: invalid literal for int(): 2+2

How do I this ? I have a string with a such expression and I want to
return the answer in a variable.

eval('2+2')
-> 4

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top