python compile code object -- reverse how to

leo lgoh at optonline.net
Wed Jul 19 18:34:39 EDT 2006


Hi,
following is the python scripts:
import marshal
script = """
print 'hello'
"""
code = compile(script, "<script>", "exec")
data = marshal.dumps(code)
print repr(data)
the result:'c\000\000\000\000\001\000\000\000s\017\000\000\00
0\177\000\000\177\002\000d\000\000GHd\001\000S(\00
2\000\000\000s\005\000\000\000helloN(\000\000\000\
000(\000\000\000\000s\010\000\000\000<script>s\001
\000\000\000?\002\000s\000\000\000\000'how to convert the result code to 
orig script """print 'hello'"""thanks





More information about the Python-list mailing list