Re: Unclear On Class Variables

2005-01-14 Thread Pierre Barbier de Reuille
Pierre Barbier de Reuille a écrit : Antoon Pardon a écrit : Well I find this a confusing behaviour on python's part. The fact that instance.field can mean something different, depending on where in a statement you find it, makes the behaviour inconsistent. I know people in general here are against

Re: Unclear On Class Variables

2005-01-13 Thread Pierre Barbier de Reuille
Antoon Pardon a écrit : Well I find this a confusing behaviour on python's part. The fact that instance.field can mean something different, depending on where in a statement you find it, makes the behaviour inconsistent. I know people in general here are against declarations, but declarations could

Re: Unclear On Class Variables

2005-01-13 Thread Antoon Pardon
> > Well I find this a confusing behaviour on python's part. The fact > that instance.field can mean something different, depending on > where in a statement you find it, makes the behaviour inconsistent. > > I know people in general here are against declarations, but declarations > could IMO provi

Re: Unclear On Class Variables

2005-01-13 Thread Fredrik Lundh
Tim Daneliuk wrote: >I am a bit confused. I was under the impression that: > > class foo(object): > x = 0 > y = 1 > > means that x and y are variables shared by all instances of a class. > But when I run this against two instances of foo, and set the values > of x and y, they are indeed unique to

Re: Unclear On Class Variables

2005-01-13 Thread Steve Holden
Tim Daneliuk wrote: I am a bit confused. I was under the impression that: class foo(object): x = 0 y = 1 means that x and y are variables shared by all instances of a class. What it actually does is define names with the given values *in the class namespace*. But when I run this against

Re: Unclear On Class Variables

2005-01-13 Thread Simon Brunning
On Thu, 13 Jan 2005 08:56:10 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote: > Simon, it's really not about mutability at all. You've changed > the example, Err, there *wasn't* an example, not really. The OP just mentioned 'setting the values' of instance members. That *can* mean name binding, bu

Re: Unclear On Class Variables

2005-01-13 Thread Peter Hansen
Simon Brunning wrote: On 13 Jan 2005 07:18:26 EST, Tim Daneliuk <[EMAIL PROTECTED]> wrote: But you are being mislead by the fact that integers are immutable. 'spam.eggs = 2' is *creating* an instance member - there wasn't one before. Have a look at what happens with a mutable object: Simon, it's re

Re: Unclear On Class Variables

2005-01-13 Thread Antoon Pardon
Op 2005-01-13, harold fellermann schreef <[EMAIL PROTECTED]>: > Hi Tim, > > If you have > > class Foo(object) : > x = 0 > y = 1 > > foo = Foo() > > foo.x # reads either instance or class attribute (class in this case) > > foo.x = val # sets an instance attribute (because foo is instance

Re: Unclear On Class Variables

2005-01-13 Thread Diez B. Roggisch
Tim Daneliuk wrote: > I am a bit confused. I was under the impression that: > > class foo(object): > x = 0 > y = 1 > > means that x and y are variables shared by all instances of a class. > But when I run this against two instances of foo, and set the values > of x and y, they are indeed unique

Re: Unclear On Class Variables

2005-01-13 Thread Antoon Pardon
Op 2005-01-13, Simon Brunning schreef <[EMAIL PROTECTED]>: > On 13 Jan 2005 07:18:26 EST, Tim Daneliuk <[EMAIL PROTECTED]> wrote: >> I am a bit confused. I was under the impression that: >> >> class foo(object): >> x = 0 >> y = 1 >> >> means that x and y are variables shared by a

Re: Unclear On Class Variables

2005-01-13 Thread harold fellermann
Hi Tim, If you have class Foo(object) : x = 0 y = 1 foo = Foo() foo.x # reads either instance or class attribute (class in this case) foo.x = val # sets an instance attribute (because foo is instance not class) Foo.x = val # sets a class attribute foo.__class.__x = val

Re: Unclear On Class Variables

2005-01-13 Thread Simon Brunning
On 13 Jan 2005 07:18:26 EST, Tim Daneliuk <[EMAIL PROTECTED]> wrote: > I am a bit confused. I was under the impression that: > > class foo(object): > x = 0 > y = 1 > > means that x and y are variables shared by all instances of a class. > But when I run this against two instances

Unclear On Class Variables

2005-01-13 Thread Tim Daneliuk
I am a bit confused. I was under the impression that: class foo(object): x = 0 y = 1 means that x and y are variables shared by all instances of a class. But when I run this against two instances of foo, and set the values of x and y, they are indeed unique to the *instance* rather