python compiled code ofuscation

Calvelo Daniel dcalvelo at pharion.univ-lille2.fr
Tue Aug 1 12:09:18 EDT 2000


Jesus Cea Avion <jcea at argo.es> wrote:

: How can I import a module from a compiled version (pyc) loaded into a
: string?.

Does the following help?

>>> import new
>>> str_mod="""class mc:\n def __init__(self):\n  print "hola!"\nmv=1"""
>>> modname=new.module("module_orig_name")
>>> exec( str_mod, modname.__dict__ )
>>> modname.mc
<class module_orig_name.mc at 808b558>
>>> inst_of_mc = modname.mc()
hola!
>>> modname.mv
1

The first argument to exec can be a string or a compile'd string.

Hasta la proxima.

Daniel.

-- Daniel Calvelo Aros
     calvelo at lifl.fr



More information about the Python-list mailing list