Hi all ; ask=raw_input("type the query: ") when i type 23+9 after this;

i wanna get '32' result..

like ;

>>>type the query: 3+5
>>>result : 8

this is what i want.. thank you..

If the query is a valid python expression, you can simply use eval: result = eval(ask) . Be careful that this will evaluate any python expression (like the expression which erases all your hard disk). You could add some validating routine to eliminate dangerous expressions (for example you could check the expression's token types with the help of module tokenize ).

Another solution is to use a parser module like wisent http://www.seehuhn.de/pages/wisent . See the example for arithmetic expressions in the wisent tutorial.