Interestingly - how imported .pyc get around this is that the
entire file is a piece of executable code which when executed
creates the other objects. ( Another fact that should have
been obvious from Python's behaviour, but I hadn't ever thought
about it before. )
There is some magic stuff in the beginning, but if you skip over
that:
>>> import marshal
>>> pycode = open( 'f.pyc', 'r' ).read()
>>> code_obj = marshal.loads( pycode[8:] ) # skip Magic id
>>> code_obj
<code object ? at 20074f78, file "./f.py", line 0>
>>> dir()
['__name__', 'code_obj', 'marshal', 'pycode']
>>> exec code_obj
>>> dir() # exec-ing code object def's entries into namespace
['__name__', 'addtodict', 'addtolist', 'code_obj', 'fac', 'fib',
'marshal', 'pycode']
>>>
[ This causes me to reconsider my previous suggestion of using
(a more complete) marshal.c to add newfuncobject( code, name,
global ) and other new*object functions to Python. Maybe I've
got it ass-backwards! ]
- Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU>
- UVA Department of Molecular Physiology and Biological Physics