Help, how to override <= operator

Clemens Hintze cle at qiao.in-berlin.de
Fri May 21 13:12:50 EDT 1999


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! :-)

[...]

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

[...]

>Me profi? Not really. Here's the implementation Arcege (Michael Reilly)
>send me, which is even better (he said: for sharing purposes, so I 
>guess he doesn't mind me repeating it here):

>class Myint:
>	def __init__(self, n = 0):
>		self.i = n
>	def __cmp__(self, other):
>		return cmp(self.i, other)
>	def __rcmp__(self, other): 
>		return cmp(other, self.i)             

>which allows you to compare your own integers with standard integers and 
>floats and longs...

Kewl!  That is the difference between me and a wizzard ;-) I will
remember that :-)

>>>> i = Myint()
>>>> 0L <= i < 0.3
>1

>Pretty cool eh?

Indeed, indeed :-))))

>Cheers, Frank

Ciao, Clemens




More information about the Python-list mailing list