CONSTRUCT - Adding Functionality to the Overall System
Damjan
gdamjan at gmail.com
Tue Sep 19 04:19:52 EDT 2006
>>> __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?
>
> Wrong.
>
> If you set __metaclass__ = type, every class in that module will be
> new-style.
>>> from UserDict import UserDict
>>> type(UserDict)
<type 'classobj'>
>>> class A(UserDict):
... pass
>>> type(A)
<type 'classobj'>
>>> __metaclass__ = type
>>> class B(UserDict):
... pass
>>> type(B)
<type 'classobj'>
It seems that NOT every class in my module will be a new style class,
especially those that inherit from other old-style classes in other
modules.
--
damjan
More information about the Python-list
mailing list