[Python-Dev] Dynamic module namspaces (original) (raw)
Johan Dahlin jdahlin at async.com.br
Sat Jul 15 20:38:04 CEST 2006
- Previous message: [Python-Dev] list.__init__() vs. dict.__init__() behaviour
- Next message: [Python-Dev] Dynamic module namspaces
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In an effort to reduce the memory usage used by GTK+ applications written in python I've recently added a feature that allows attributes to be lazy loaded in a module namespace. The gtk python module contains quite a few attributes (around 850) of which many are classes or interfaces (150+)
The changes to PyGTK I had to make can not be considered anything but a hack; I had to put a subclass of a ModuleType in sys.modules and override getattribute to be able to get old code which accessed gtk.dict directly to still work (PyModule_GetDict requires that). However, even if I didn't have to use getattribute overriding sys.modules is rather unpleasent and I'm afraid it'll cause problems in the future.
My point is that I consider this to be a valid use case, the amount of saved memory is significan, and I could not find another way of doing it and still keep the gtk interface (import gtk; gtk.Button) to still be backwards compatible.
What I want to ask, is it possible to have a sanctioned way to implement a dynamic module/namespace in python?
For instance, it could be implemented to allow you to replace the dict attribute in a module with a user provided object which implements the dictionary protocol.
Johan
- Previous message: [Python-Dev] list.__init__() vs. dict.__init__() behaviour
- Next message: [Python-Dev] Dynamic module namspaces
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]