Posted By

cthulhupunk0 on 06/04/09


Tagged

metaclass


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

saman


Metaclass example


 / Published in: Python
 

  1. class ChattyType(type):
  2. def __new__(cls, name, bases, dct):
  3. print "Allocating memory for class", name
  4. return type.__new__(cls, name, bases, dct)
  5.  
  6. def __init__(cls, name, bases, dct):
  7. print "Init'ing (configuring) class", name
  8. super(ChattyType, cls).__init__(name, bases, dct)
  9. X = ChattyType('X',(),{'foo':lambda self:'foo'})

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: cthulhupunk0 on June 4, 2009

BTW, this is not my original. I'm just testing out my snipplr plugin in gedit, and this was convenient. I just checked the file this was taken from, and don't have a url for citation (sorry), but if anyone knows where this is from please post.

You need to login to post a comment.