Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Emulating C++ namespaces with ChainMap and metaclass trickery

Reply
Thread Tools

Emulating C++ namespaces with ChainMap and metaclass trickery

 
 
Steven D'Aprano
Guest
Posts: n/a
 
      10-03-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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Metaclass of a metaclass Steven D'Aprano Python 1 06-05-2012 03:30 PM
array copy via "struct-trickery" anon.asdf@gmail.com C Programming 8 08-31-2007 09:14 AM
What camera trickery could I use to make objects appear larger than they really are? Jeff Ingram Digital Photography 17 06-18-2005 03:28 PM
metaclass that inherits a class of that metaclass? ironfroggy Python 16 06-03-2005 10:00 AM
Registry trickery? G*rd*n HTML 13 11-07-2004 01:21 PM



Advertisments