New-style classes questions

Gerrit Holl gerrit at nl.linux.org
Sun Sep 25 09:24:29 EDT 2005


Diez B. Roggisch wrote:
> > What is the reason for allowing both styles? (backwards compatibility??) 
> 
> yes.

Note that there is another way to create new-style classes:

__metaclass__ = type

before the first class definition:

>>> class Foo: pass
...
>>> type(Foo)
<type 'classobj'>
>>> __metaclass__ = type
>>> class Bar: pass
...
>>> type(Bar)
<type 'type'>

I like this. However, perhaps other people reading my source code won't
like it, because when they see 'class Foo:', they might expect an
old-style class. But it's so much better to type and to read, that I
prefer this.

Does the Python style guide have any severe penalty for using this?

regards,
Gerrit.

-- 
Temperature in Luleå, Norrbotten, Sweden:
| Current temperature   05-09-25 15:19:47   11.0 degrees Celsius ( 51.9F) |
-- 
Det finns inte dåligt väder, bara dåliga kläder.



More information about the Python-list mailing list