parsing equations

M

munehiro

hi all,

i have a question.
Given the string '3+2*6' i need to parse it and obtain the result, so
15. Does a module for this operation exists? i need to do simple
operations, but also on floating point numbers.

many thanks
 
D

Diez B. Roggisch

i have a question.
Given the string '3+2*6' i need to parse it and obtain the result, so
15. Does a module for this operation exists? i need to do simple
operations, but also on floating point numbers.

Use the builtin function eval to evaluate an arbitrary python expression:
15


Regards,

Diez
 
P

Peter Otten

Diez said:
Use the builtin function eval to evaluate an arbitrary python expression:

15

Be aware that this is powerful:
'done'

Just to make sure the OP is aware of the inherent danger of the unsuspecting
"arbitrary python expression"...

Peter
 
D

Diez B. Roggisch

Be aware that this is powerful:
'done'

Just to make sure the OP is aware of the inherent danger of the
unsuspecting "arbitrary python expression"...

Yup - should have mentioned that.

Diez
 

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

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top