En Fri, 20 Jul 2007 12:48:05 -0300, Prepscius, Colin (IT)  
<[EMAIL PROTECTED]> escribió:

> Does anybody know how to pass parameters to 'exec
> somefunction.func_code'?
> def f1():
>     print 'this is f1'
> def f2(p):
>     print 'this is f2, p =', str(p)
> exec f1.func_code
> THIS RESULTS IN:  "this is nf1"   WHICH IS NICE
> exec f2.func_code
> THIS RESULTS IN:  TypeError: f2() takes exactly 1 argument (0 given)
> WHICH IS EXPECTED

Instead of using exec, rebuild a new function from the unmarshalled code:

import new
f3 = new.function(f2.func_code, globals())
f3(parameter)

-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to