Andreas Löscher wrote:
import types
import marshal
def a(): pass
...
s=marshal.dumps(a.__code__)
f=types.FunctionType(marshal.loads(s), {})
f
<function a at 0x7f6308a66de8>
What version of python do you have? If I try your code above I get :

 >>> import types
 >>> import marshal
 >>> def a(): pass
...
 >>> s=marshal.dumps(a.__code__)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute '__code__'


I used Version 2.6 for this. __code__ is just an alias for func_code.

def a(): pass
...
s=marshal.dumps(a.func_code)

This should allways work, unless the implementation of the function
object changes. (I have tested it under 2.4, 2.5 and 2.6, but it should
also work in further versions)

Best,
Andreas

Yes, it works, thank you,
Gabriel
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to