Codeobjects of Modules?

Stefan Migowsky smigowsky at dspace.de
Thu Jun 21 11:09:05 EDT 2001


Hi,

if you want to read the code object from a pyc module use this code.

import marshal
File = open(r"c:\temp\test.pyc","rb")
File.read(8)  # Magic number etc. 
code = marshal.load(File)
File.close()

The code has the same format as the code objects you find
in func_code etc.

You can execute the code by simply do an exec

import __main__ 
exec code in __main__.__dict__

	Stefan


> 
> > ----------
> > Von: 	gbgbgb at gmx.de[SMTP:GBGBGB at GMX.DE]
> > Gesendet: 	Donnerstag, 21. Juni 2001 08:29:34
> > An: 	python-list at cwi.nl
> > Betreff: 	Codeobjects of Modules?
> > Diese Nachricht wurde automatisch von einer Regel weitergeleitet.
> > 
> 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!
> 
> gunter
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 




More information about the Python-list mailing list