[EMAIL PROTECTED] wrote:

> It is possible to get bytecode from code object.
> Reversely, is it possible to create code object from bytecode?
> 
> ex.
>   ## python code (not a module)
>   pycode = '''\
>   print "<ul>\n"
>   for item in items:
>       print "<li>%s</li>\n" % item
>   print "</ul>\n"
>   '''
> 
>   ## compile it and get bytecode
>   code = compile(pycode, kind='exec')
>   bytecode = code.co_code
>   open('hoge.pyc', 'wb').write(bytecode)
> 
>   ## load bytecode and eval it
>   bytecode = open('hoge.pyc', 'rb').read()
>   code = create_code(bytecode)    ## how to ?????
>   output = eval(code, globals, {'items': ['A', 'B', 'C']})

use the marshal module; see the last script on this page for an example:

     http://effbot.org/librarybook/marshal

</F>

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to