Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Emulating C++ namespaces with ChainMap and metaclass trickery

20 views
Skip to first unread message

Steven D'Aprano

unread,
Oct 3, 2012, 2:26:50 PM10/3/12
to
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
0 new messages