class variables for subclasses tuple

Peter Otten __peter__ at web.de
Wed Mar 8 04:36:03 EST 2006


alainpoint at yahoo.fr wrote:

> Point.x=0 leads to having p.x==0
> It seems not possible to have class variables and instance variable
> having the same name and yet different values.

A quick check:
 
>>> class T(tuple):
...     class __metaclass__(type):
...             x = property(lambda cls: 0)
...     x = property(lambda self: self[0])
...
>>> t = T("abc")
>>> t.x
'a'
>>> T.x
0

So possible it is. Come back if you're stuck generalizing the above.

Peter




More information about the Python-list mailing list