load a class dynamically

Jeremy Lowery jslowery at hotmail.com
Sat Dec 1 05:19:42 EST 2001


Ok, I see how that would help me out.
I've been thinking, maybe my approach is entirely wrong. I'm hitting
wall after wall after wall.
Hypothetically speaking...what would be the best way to write a program
that...

loaded a python source file that only contained class or function
definitions.
Put the code in the database(bytecode, sourcecode, whatever)
And then loaded and executed that code in  a "virtual sandbox." the sandbox
so-to-speak would be a restricted execution environment.

loaded another python source file that used classes and functions in
the first source file.
Put that code in the database(bytecode, sourcecode, whatever)
And then loaded and executed that code in the current "virtual sandbox."

So basically I'd just collectively be loaded class and object definitions
into memory (of course, the program could shutdown and be restarted and
things would still be the same way because they were stored in the dbase.)

And as icing on the cake, the code in the database would need to be able to
be changed by the user.

I've been pounding on this for about 2 days now, any ideas about this would
be greatly appreciated. The package, module stuff is just "extra"

Jeremy

"Fernando Pérez" <fperez528 at yahoo.com> wrote in message
news:9ua14i$l9t$1 at peabody.colorado.edu...
> Jeremy Lowery wrote:
>
> > Now I'm in search of finding a way to make a dynamic modules,
> > packages to add the classes to. I'm writing an app that stores all
> > of this stuff in a ZODB and lets users write code on a server over a
> > network. And I'm trying to figure out a way to dynamically "pack"
> > all of the class definitions into modules and packages so that I can
> > plug the base package into the namespace before the code is run.
> >
> > like one user importing Users.JLowery.ACoolModule
> > in the code that is going to be piped over the network, and then the
> > module/package structure is dynamically created from the objects in
> > the ZODB. (Like the User package gets put in the global namespace)
> > (Of course, not dynamically recreate it on every request but you get
> > the idea.)
> >
> > Jeremy
> >
> >
> >
>
> Never mind the funny variable names, but this does exactly (I think)
> that:
>
>     for _t.mod in __IP.rc.import_mod:
>         try:
>             exec 'import '+_t.mod in locals()
>         except :
>             __IP.InteractiveTB()
>             import_fail_info(_t.mod)
>
> __IP.rc.import_mod is a list of strings with names of modules which
> get loaded into the user namespace after the program is running.
>
> Does this help?
>
> f






More information about the Python-list mailing list