Emulating C++ namespaces with ChainMap and metaclass trickery
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Oct 3 14:26:50 EDT 2012
C++ namespaces are useful for encapsulating related objects within a
single file, subdividing the global namespace without using classes.
Python has modules, but they come in separate files.
Using Python 3.3's ChainMap type, and some metaclass trickery, I abuse
the class keyword to (almost) emulate C++ namespaces:
http://code.activestate.com/recipes/578279/
--
Steven
More information about the Python-list
mailing list