Re: class variables for subclasses tuple

2006-03-08 Thread Peter Otten
[EMAIL PROTECTED] wrote: > In passing, I have another question: where can I read up more on > metaclasses? Well, in "Python in a Nutshell" Alex Martelli manages to pack the practical information that lets you work with metaclasses into just four pages, including a two-page example. You may have s

Re: class variables for subclasses tuple

2006-03-08 Thread alainpoint
Thank you Peter, this does the job. In passing, I have another question: where can I read up more on metaclasses? Alain -- http://mail.python.org/mailman/listinfo/python-list

Re: class variables for subclasses tuple

2006-03-08 Thread Peter Otten
[EMAIL PROTECTED] wrote: > > Peter Otten wrote: >> [EMAIL PROTECTED] 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): >> ...

Re: class variables for subclasses tuple

2006-03-08 Thread alainpoint
As an supplement to my previous post, please find hereunder a snippet for my unsuccessful attempt (commented out snippet does not work): def superTuple(*attribute_names): nargs = len(attribute_names) class T(tuple): def __new__(cls, *args): re

Re: class variables for subclasses tuple

2006-03-08 Thread alainpoint
Peter Otten wrote: > [EMAIL PROTECTED] 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): > ...

Re: class variables for subclasses tuple

2006-03-08 Thread Peter Otten
[EMAIL PROTECTED] 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) ..

class variables for subclasses tuple

2006-03-08 Thread alainpoint
Hello, I have got a problem that i can't readily solve. I want the following: I want to create a supertuple that behaves both as a tuple and as a class. It should do the following: Point=superTuple("x","y","z") # this is a class factory p=Point(4,7,9) assert p.x==p[0] assert p.y==p[1] assert p.z==