Transforming a str to an operator

Xavier Ho contact at
Fri Aug 28 06:01:16 CEST 2009

On Fri, Aug 28, 2009 at 1:52 PM, Duke Normandin <dukeofperl at> wrote:

> 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!

Maybe you were looking for

print eval(num1 + op + num2) # it's a little ugly string concatenation.

Hm? (untested, but it works in my head.)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list