Re: Class variables static by default?

2009-12-22 Thread Daniel Fetchinson
>> I don't think Steven cares much, he loves this type of nitpicking and >> uber pedantic formulations, but only if he can apply it to other >> people's post :) > > Heh heh :) > > I actually do care, because (not having a Java/C++ background) I actually > do get a mental "double-take" every time I

Re: Class variables static by default?

2009-12-21 Thread Steven D'Aprano
On Mon, 21 Dec 2009 15:03:03 +0100, Daniel Fetchinson wrote: > I don't think Steven cares much, he loves this type of nitpicking and > uber pedantic formulations, but only if he can apply it to other > people's post :) Heh heh :) I actually do care, because (not having a Java/C++ background) I a

Re: Class variables static by default?

2009-12-21 Thread Daniel Fetchinson
>>> In python, 'class variable' is a variable that belongs to a class; not >>> to the instance and is shared by all instance that belong to the class. >> >> Surely, since string variables are strings, and float variables are >> floats, and bool variables are bools, and module variables are modules,

Re: Class variables static by default?

2009-12-20 Thread Gabriel Genellina
En Sun, 20 Dec 2009 01:16:16 -0300, Steven D'Aprano escribió: On Sun, 20 Dec 2009 11:44:11 +1100, Lie Ryan wrote: In python, 'class variable' is a variable that belongs to a class; not to the instance and is shared by all instance that belong to the class. Surely, since string variables are

Re: Class variables static by default?

2009-12-20 Thread Steven D'Aprano
On Sat, 19 Dec 2009 20:28:07 -0800, Chris Rebert wrote: >> Surely, since string variables are strings, and float variables are >> floats, and bool variables are bools, and module variables are modules, >> a class variable will be a class and an instance variable will be an >> instance? > > As the

Re: Class variables static by default?

2009-12-19 Thread Chris Rebert
On Sat, Dec 19, 2009 at 8:16 PM, Steven D'Aprano wrote: > On Sun, 20 Dec 2009 11:44:11 +1100, Lie Ryan wrote: > >> In python, 'class variable' is a variable that belongs to a class; not >> to the instance and is shared by all instance that belong to the class. > > Surely, since string variables ar

Re: Class variables static by default?

2009-12-19 Thread Steven D'Aprano
On Sun, 20 Dec 2009 11:44:11 +1100, Lie Ryan wrote: > In python, 'class variable' is a variable that belongs to a class; not > to the instance and is shared by all instance that belong to the class. Surely, since string variables are strings, and float variables are floats, and bool variables ar

Re: Class variables static by default?

2009-12-19 Thread Lie Ryan
On 12/20/2009 11:10 AM, KarlRixon wrote: Given the following script, I'd expect p1.items to just contain ["foo"] and p2.items to contain ["bar"] but they both contain ["foo", "bar"]. Why is this? Are object variables not specific to their instance? First of all, dump all the preconception of w

Re: Class variables static by default?

2009-12-19 Thread Cameron Simpson
On 19Dec2009 16:10, KarlRixon wrote: | Given the following script, I'd expect p1.items to just contain | ["foo"] and p2.items to contain ["bar"] but they both contain ["foo", | "bar"]. | | Why is this? Are object variables not specific to their instance? You haven't instatiated "items" in the ob

Re: Class variables static by default?

2009-12-19 Thread Xavier Ho
Yes, if you want instance variables that are unique to each instance of a class, do the following: class Parser: def __init__(self): self.items = [] And that should work fine. J:\_Programming Projects\Python>python test.py <__main__.Parser object at 0x0240E7B0> <__main__.Parser object

Re: Class variables static by default?

2009-12-19 Thread John Posner
On Sat, 19 Dec 2009 19:10:13 -0500, KarlRixon wrote: Given the following script, I'd expect p1.items to just contain ["foo"] and p2.items to contain ["bar"] but they both contain ["foo", "bar"]. Why is this? Are object variables not specific to their instance? --- #!/u

Re: class variables and class methods

2009-04-18 Thread Aahz
In article <9c848013-2245-455e-bb30-48e430d56...@j9g2000prh.googlegroups.com>, wrote: > >I have a class whose job is to serve several other objects, [...] Sorry, I'm finding it difficult to understand what you want. It looks to me that you're confusing "object" and "instance", and I think you'

Re: class variables

2006-08-08 Thread Andre Meyer
On 7/31/06, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Colin J. Williams wrote: > > Andre Meyer wrote: > >> Hi all > >> > >> I am trying to understand the magic of Python's class variables and > >> tried the following code (see below). > >> > >> Just out of curiosity, I tried to define a prop

Re: class variables

2006-07-31 Thread Bruno Desthuilliers
Colin J. Williams wrote: > Andre Meyer wrote: >> Hi all >> >> I am trying to understand the magic of Python's class variables and >> tried the following code (see below). >> >> Just out of curiosity, I tried to define a property that provides >> access to a seemingly instancae variable which is in

Re: class variables

2006-07-30 Thread faulkner
python != java. when you say "self.v = ...", you mask the class attribute with an instance attribute. say "C1.v = ...". Colin J. Williams wrote: > Andre Meyer wrote: > > Hi all > > > > I am trying to understand the magic of Python's class variables and > > tried the following code (see below). > >

Re: class variables

2006-07-30 Thread Colin J. Williams
Andre Meyer wrote: > Hi all > > I am trying to understand the magic of Python's class variables and > tried the following code (see below). > > Just out of curiosity, I tried to define a property that provides access > to a seemingly instancae variable which is in fact a class variable. All >

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) ..