[Python-Dev] Assignment to class of module? (Autoloading? (Making Queue.Queue easier to use)) (original) (raw)
Phillip J. Eby pje at telecommunity.com
Thu Oct 13 04:16:57 CEST 2005
- Previous message: [Python-Dev] Assignment to __class__ of module? (Autoloading? (Making Queue.Queue easier to use))
- Next message: [Python-Dev] Assignment to __class__ of module? (Autoloading? (Making Queue.Queue easier to use))
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 01:47 PM 10/13/2005 +1300, Greg Ewing wrote:
I just tried to implement an autoloader using a technique I'm sure I used in an earlier Python version, but it no longer seems to be allowed.
I'm trying to change the class of a newly-imported module to a subclass of types.ModuleType, but I'm getting TypeError: class assignment: only for heap types Have the rules concerning assignent to class been made more restrictive recently?
It happened in Python 2.3, actually. The best way to work around this is to add an instance of your subclass to sys.modules first, then call reload() on it to make the normal import process work. PEAK uses this to implement lazy loading.
Actually, for your purposes, you might be able to just replace the module object and copy its contents to the new module's dictionary.
- Previous message: [Python-Dev] Assignment to __class__ of module? (Autoloading? (Making Queue.Queue easier to use))
- Next message: [Python-Dev] Assignment to __class__ of module? (Autoloading? (Making Queue.Queue easier to use))
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]