Making classes from Metaclasses globally available

Michele Simionato michele.simionato at poste.it
Wed Jun 16 23:58:20 EDT 2004


Jacek Generowicz <jacek.generowicz at cern.ch> wrote in message news:<tyfy8mn8v5o.fsf at pcepsft001.cern.ch>...
> (though in one case I would like to try having a third namespace
> similar to globals and builtins where to shove all this stuff
> ... unfortunately I haven't found a satisfactory way of creating one
> yet.)

I do not understand what the problem is ... you can just create a
class (or instance) called namespace, put it in __builtin__ and call
all the names in this custom namespace as namespace.myname.
Maybe you do not like to tweak with __builtin__ (which I can understand);
another option is to use a dynamically created module to fake a namespace:

import sys
from types import ModuleType

sys.modules["namespace"] = ModuleType("namespace",
                       """This is a dynamically generated module used to
                       fake a namespace.""")

#populate it with setattr, getattr


I am sure you thought to this solution too, so what is unsatisfactory about it?
Just to know,


                  Michele Simionato



More information about the Python-list mailing list