module from BLOB

Bjorn Pettersen BPettersen at NAREX.com
Mon Feb 4 13:32:38 EST 2002


> From: Fredrik Lundh [mailto:fredrik at pythonware.com] 
> 
> marcin andrzejewski wrote:
> > is it possible to import module directly from database 
> BLOB/CLOB field 
> > ?
> 
> something like this could work:
> 
> import imp, marshal
> from my_database_api import fetch_blob_from_database
> 
> def import_from_blob(name):
>     # fetch code object
>     code = marshal.loads(fetch_blob_from_database(name))
>     # create a new module object
>     module = imp.new_module(name)
>     # execute the code in the module's namespace
>     exec code in vars(module)
>     return module

Don't you also have to say:

  sys.modules[name] = module

Or am I missing something?

-- bjorn




More information about the Python-list mailing list