[Python-Dev] __pycode__ extension

Stelios Xanthakis sxanth at ceid.upatras.gr
Tue Nov 16 20:21:41 CET 2004



On Tue, 16 Nov 2004, Jeremy Hylton wrote:

> Functions already have a reference to code objects.  How is this different?

This is the python-code text.

>>> def foo ():
...     # comment -- instead of doc
...     print 'santa'
...
>>> print foo.__pycode__
def foo():
     # comment -- instead of doc
     print 'santa'


This is fun as I explained in the post at c.l.p
because with a function:

def save(FILE):
     for a in globals():
         if type(eval(a)) == FunctionType:
             FILE.write (eval(a).__pycode__)

We can save the entire state in a file
and continue from there next time.

Stelios



More information about the Python-Dev mailing list