Hello
I need to either call exec() or eval() based on an input string "s"
If "s" was an expression, after calling eval() I want to print the result if the result was not None
If "s" was a statement then simply exec(). If the statement happens to print something then so be it.
s = "1 == 2" # user input # --- try: v = eval(s) print "v->", v except: print "eval failed!" # --- try: exec(s) except: print "exec failed!"
For example, "s" can be:
s = "print 123"
And in that case, exec() should be used.
Ofcourse, I don't want to try first eval() and if it fails call exec()