__metaclass__ = type (was: Re: if (__name__ == '__main__'): main(sys.argv[1:]))

Michael Hudson mwh at python.net
Thu Apr 22 06:18:16 EDT 2004


Lee Harr <missive at frontiernet.net> writes:

> On 2004-04-21, François Pinard <pinard at iro.umontreal.ca> wrote:
> >
> > __metaclass__ = type
> >
> > class Main:
> >     def __init__(self):
> >         pass
> >
> 
> > A word about the `__metaclass__' line.  My intent is to forget all about
> > classic classes and go with the new type system as quickly as possible.
> > I do not want to derive each and every of my classes from `object',
> > and later edit all those `(object)' out when the classic classes will
> > effectively get deprecated.  Much easier and cleaner to remove that
> > `__metaclass__' line then.  Moreover, by using this `__metaclass__' line
> > in all my things, I do not risk obscure bugs because I forgot one of
> > these `object' derivation while I used more recent Python features.
> >
> 
> 
> Very interesting.
> 
> Is there any reason to stick with old-style classes? Or would we all
> be well-advised to use something like this?

I'd say, just inherit from object all the time.

> I mostly just create classes the old way and never even think about
> subclassing object.

Tsk!

BTW, my slides from PythonUK on this kind of thing are online at

    http://starship.python.net/crew/mwh/hacks/

Cheers,
mwh

-- 
  Indeed, when I design my killer language, the identifiers "foo" and
  "bar" will be reserved words, never used, and not even mentioned in
  the reference manual. Any program using one will simply dump core
  without comment. Multitudes will rejoice. -- Tim Peters, 29 Apr 1998



More information about the Python-list mailing list