help on eval()-like but return module object

D

Dody Suria Wijaya

As I'm adding XMLRPC support in my apps, I'd like to send a module in
server to be executed in client. My plan in sending the file content via
xmlrpc, and doing compile + eval, but eval just execute the code object
without returning the module.

Original:

import mymodule
mymodule.run(request)

Wish:

string_code = rpc_con.GetModule('mymodule')
code_obj = compile(string_code, '<string>', 'exec')
mymodule = eval(code_obj)
mymodule.run(request)

Any helps on this topic would be highly appreciated. Thanks!
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Dody said:
Any helps on this topic would be highly appreciated. Thanks!

You can use new.module to create a new module, and exec to
execute some code in the module:

py> m = new.module("Hallo")
py> exec "a=3" in m.__dict__
py> m.a
3
py> m
<module 'Hallo' (built-in)>

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,276
Messages
2,571,384
Members
48,073
Latest member
ImogenePal

Latest Threads

Top