Codeobjects of Modules?

Drew Csillag drew.csillag at starmedia.net
Fri Jun 22 09:13:40 EDT 2001


On Thu, Jun 21, 2001 at 07:29:34AM -0000, gbgbgb at gmx.de wrote:
> Hi!
> I am writing an experimental virtual machine for Python-Byte-Code
> in Python. It works fine for Functions (I am using the
> f.func_code.co_code Bytecode.)
> 
> Now I want to run entire pyc-Files and/or modules. How do I get the
> bytecode from modules and what is the format of the pyc-files. I could
> not find any documentation. 
> 
> After finishing the PVM in Python I want to port it to - please do not
> kill me - JAVASCRIPT. I think this could be interesting to be able to
> execute python-byte-code on NS and IE without JAVA.
> 
> Any help is welcome!

To get the code object:

import marshal
f = open(filename)
f.seek(8)
code_obj = marshal.load(f)

That's it!

Cheers,
Drew

-- 
print(lambda(m,d,y):['Tues','Wednes','Thurs','Fri','Satur','Sun','Mon'][
((d-((0,3,7,7,4,9,6,4,8,5,3,7,5)[m]+(m<3and(y%4==0)and y%100!=0or y%400
==0)))+(lambda(q,r),y:(q+r+r/4+(-2*(y%4))))(divmod(y%100,12),y/100))%7]+
'day')(map(int,raw_input('mm/dd/yyyy>').split('/')))





More information about the Python-list mailing list