Help, how to override <= operator

Michael Hudson mwh21 at cam.ac.uk
Sun May 23 13:01:03 EDT 1999


cle at qiao.in-berlin.de (Clemens Hintze) writes:

> Frank Niessink <frankn=news at cs.vu.nl> writes:
> 
> >Clemens Hintze <cle at qiao.in-berlin.de> wrote:
> 
> >> Ahem, oh, uh! You're right, of course. I ever initialize instance
> >                                          ^^^^^ did you mean: never?
> 
> No I meant EVER! :-)

"always" is a more English word in this context. "ever" does mean the
same, but it's a bit archaic. I thought I knew what you meant the
first time, for what it's worth.
 
> [...]
> 
> >I'm a bit confused about what you here. 
> 
> It is not so important. I mean, that I often initialize instance
> variables within the class definition statement first. If "__init__"
> has to initialize them afterwards again to another value, I welcome
> it.
> 
> As you know, during read access Python will access "class" variables,
> if concerning instance variables doesn't exist.
> 
> Furthermore that way I can often see on the first blink, what variable
> are used by my class.

Fine, just don't ever do this when you are initializing a variable
with a mutable value or you're likely to confuse yourself. This was
the source of my recent diatribe against class variables on this list
(although I've moderated my position a little since then).

class ThisIsNotABugAndIWillNotPostToTheNewsgroupClaimingItIs:
    value = []
    def __init__(self,a):
         self.value.append(a)

a=ThisIsNotABugAndIWillNotPostToTheNewsgroupClaimingItIs(1)
print a.value  => [1]

b=ThisIsNotABugAndIWillNotPostToTheNewsgroupClaimingItIs(2)
print b.value  => [1,2]
print a.value  => [1,2]

I-apologize-if-you-knew-this-already-ly y'rs Michael




More information about the Python-list mailing list