CONSTRUCT - New/Old Style Classes, build-in/extension types
Steve Holden
steve at holdenweb.com
Fri Sep 22 12:34:30 EDT 2006
Paul Boddie wrote:
> Ilias Lazaridis wrote:
[...]
>>Have those old style classes any benefits?
>
>
> That you don't have to write the bizarre conceptual accident that is
> "(object)" when declaring a "top-level" class?
>
Though of course the easiest way to enforce your classes to new style is
to begin each module with
__metaclass__ = type
>>> __metaclass__ = type
>>> class X: pass
...
>>> X
<class '__main__.X'>
>>> X()
<__main__.X object at 0x186c6f0c>
>>> x = X()
>>> isinstance(x, object)
True
>>> type(x), type(X)
(<class '__main__.X'>, <type 'type'>)
>>>
regards
Steve
--
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
mailing list