How to print pass arguments to code object via exec and print in python? -


how print pass arguments code object via exec , print in python? below few examples see how things work in generic case.

def foo(x, y):     return x * y  exec(foo.func_code {'x': 1, 'y': 5}) # didn't work  def bar():     return 3*5  exec(bar.func_code) # got executed couldn't print it? 

i don't think you'll able pass arguments code object without using "black magic". why not use exec("print foo(1, 5)")?

in both examples, nothing printed because exec executes xxx.func_code, function foo , bar contain no print statements.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -