CONSTRUCT - New/Old Style Classes, build-in/extension types

Ilias Lazaridis ilias at lazaridis.com
Fri Sep 22 14:29:04 EDT 2006


Steve Holden wrote:
> 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

I assume placing this in the central site import (e.g.
sitecustomize.py) would collapse python? (I don't want to try it, maybe
someone has an isolated instance available for trials).

>   >>> __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'>)
>   >>>




More information about the Python-list mailing list