Question: is it possible to reverse engineer python objects into a string?
Info: I'm working on a project right now that distributes my prof's research across several dozen computers instead of just his. Being a good programmer I'm making it a generalized program that can be used for more than just his specific program. So the computers that will be running his code do not and will not have his .py files for them to import. The way I've gotten around this in the past is he just has to have everything in one file and pass the path to that file to my system which then imports that code as a from its state as a string (using the information gleaned from this question).
But that made me wonder. I can now import from a string and have the code execute fine and dandy. thats all well and good, but it made me think, is there a way for me to get around having to have him pass his code file to me? particularly I'm wondering something like this. say he has all of this in his file:
def hello():
print "Hello world!"
upon importing this file "hello" would be added to the global namespace. but now I want to transfer it across the network. you can't call pickle on "hello" and have it work, I've tried, pickle out right refuses.
on the other end I have the node computers using "exec code in newMod.dict" to get the code created. so if I could take "hello" and push it through some function that returns to me "def hello():\n print \"Hello world!\"" so that my exec method could then run. I would be golden. I could then make it so he could have more than just 1 file because I could just reverse engineer any non-standard imports he has.
I'm honestly expecting the answer to be no, but i figured it is worth a shot. Simply stated again, I want to take an module that has been imported and convert it into a string.