KBD

Keith Devens .com

Friday, July 4, 2008 Flag waving
Crying is all right in its way while it lasts. But you have to stop sooner or later, and then... – C.S. Lewis (The Silver Chair, ch 2)

Tag: Metaclasses

Parents:

Daily link icon Wednesday, December 14, 2005

Python's metaclasses

Dev Shed has an excellent introduction to Python's metaclasses (via DPU). I get it now:

  • Python's metaclasses are just normal classes that inherit from type
  • When you instantiate a metaclass the object returned is itself a class
  • To declare that a class has a given metaclass, set the __metaclass__ data member to the metaclass when declaring the class.
  • The metaclass' __init__ method is called when a class that has it as its metaclass is declared (__init__ for metaclasses takes (klass, klass_name, base_classes, dict_of_attributes) as its parameters).

And that's it (according to the article). So, it seems that Python very nearly has a prototype-based object system, but not quite. (And I ❤ prototype-based object systems.) With a prototype-based object system the distinction between metaclasses and classes (heck, and objects) goes away, so it seems to me that you could do the same thing as what Python calls metaclasses simply by overriding a particular object's clone method. Am I wrong?

July 2008
SunMonTueWedThuFriSat
 12345
6789101112
13141516171819
20212223242526
2728293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 5 posts

Recent comments XML

Girls, please don't get breast implants

> And no, you will not be receiving​a picture.

:-(...

Keith: Jul 2, 6:05am

Javascript clone function

This is a clever way to clone an​object if you are using YAHOO UI.​Same tec...

Antonio: Jul 1, 12:47pm

I hate Norton Antivirus

Oh just one other thing norton is​great at keeping people out of your​compu...

kevin.sands: Jul 1, 12:50am

Terminator 3 was awful

I think the biggest reason why T3​totally blew was because Edward​Furlong g...

76.167.172.64: Jun 29, 3:06am

Generated in about 0.119s.

(Used 10 db queries)

mobile phone