import - reverse engineering python to strings -
question: possible reverse engineer python objects string?
info: i'm working on project right distributes prof's research across several dozen computers instead of his. being programmer i'm making generalized program can used more specific program. computers running code not , not have .py files them import. way i've gotten around in past has have in 1 file , pass path file system imports code state string (using information gleaned this question).
but made me wonder. can import string , have code execute fine , dandy. thats , good, made me think, there way me around having have him pass code file me? particularly i'm wondering this. has of in file:
def hello(): print "hello world!" upon importing file "hello" added global namespace. want transfer across network. can't call pickle on "hello" , have work, i've tried, pickle out right refuses.
on other end have node computers using "exec code in newmod.dict" code created. if take "hello" , push through function returns me "def hello():\n print \"hello world!\"" exec method run. golden. make have more 1 file because reverse engineer non-standard imports has.
i'm expecting answer no, figured worth shot. stated again, want take module has been imported , convert string.
although it's not approach, can pickle __code__ function...
>>> def foo(): ... print "hello" >>> import pickle >>> code = pickle.dumps(foo.__code__) >>> def bar(): ... pass >>> bar() >>> bar.__code__ = pickle.loads(code) >>> bar() hello
Comments
Post a Comment