Storing a function

Kuros kurosknight at gmail.com
Sun May 25 17:00:12 EDT 2008


Hi,
Hoping I could get some help with a python question.

I want to be able to store the code for a single function in a .py file,
such as:

def test():
    print "Test"

>From within a Python script, I would like to be able to get a handler so I
can do something like:

handler.test()

I want to be able to store the handlers in a blob in a SQLite DB.
Essentially, I want to store a compiled version of a function. I have tried
using compile() and exec, and while it sort of works, it seems to import the
code into the global namespace. I can do:

x = compile(file.read(), "<x>", 'exec')
exec x
test()

and it calls test, but I may have several functions with the same name, all
read from different files. So I need to be able to do handler.test().

Any advice would be greatly appreciated!

-Kuros
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080525/c03bbb8d/attachment.html>


More information about the Python-list mailing list