Transforming a str to an operator
Duke Normandin
dukeofperl at ml1.net
Thu Aug 27 23:52:56 EDT 2009
Hey....
I'm a Python noob....
So far so good!
I've written the following:
num1 = raw_input('Enter the first number: ')
num2 = raw_input('Enter the second number: ')
op = raw_input('Select one of the following [+-*/]: ')
print 'The answer is: ', int(num1), eval(op), int(num2)
^^^^^^^^
How do I convert the contents of "op" from a string to an actual
arithmetic operator? eval() does not seem to be the answer. TIA!
--
duke
More information about the Python-list
mailing list