CONSTRUCT - Adding Functionality to the Overall System
steve at holdenweb.com
Mon Sep 18 14:23:07 CEST 2006
Ilias Lazaridis wrote:
> Damjan wrote:
>>>>I understand that I can use __metaclass__ to create a class which
>>>>modifies the behaviour of another class.
>>>>How can I add this metaclass to *all* classes in the system?
>>>>(In ruby I would alter the "Class" class)
>>>You'd have to set
>>>__metaclass__ = whatever
>>>at the top of each module whose classes are to get the new behavior.
>>I think '__metaclass__ = whatever' affects only the creation of classes that
>>would otherwise be old-style classes?
> It seems so:
>>>You can't alter classes which you don't control or create in your code.
>>I remeber I've seen an implementation of import_with_metaclass somewhere on
>>IBM's developerworks. I didn't quite undersntad it though.
> I am not so much interested in old-style, as is start production with
> python 2.4 (possibly even with python 2.5).
The fact remains that you won't be able to affect the built-in classes
such as int and str - they are hard-coded in C (for CPython, at least),
and so their metaclass is also implied and cannot be changed.
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list