[Python-Dev] ++x oddnes
Moshe Zadka
m@moshez.org
Mon, 13 Aug 2001 19:12:19 +0300 (IDT)
On Mon, 13 Aug 2001, "Fredrik Lundh" <fredrik@pythonware.com> wrote:
> try this:
>
> class StupidCounter:
> count = 0
> def __pos__(self):
> self.count = self.count + 1
> return 0 # ignore extra __pos__ calls
> def __int__(self):
> return self.count
> def __repr__(self):
> return repr(self.count)
>
> c = StupidCounter()
> print c
> ++c
> print c
Everybody is ignoring the obvious correct way to do it:
class StupidCounter:
count = 0
def __pos__(self):
self.count = self.count+0.5
return self
def __repr__(self): return str(int(self.count))
def __int__(self): return int(self.count)
Let me just add, muhahahahahahahahahahahahaha!!!!!!
--
The Official Moshe Zadka FAQ: http://moshez.geek
The Official Moshe Zadka FAQ For Dummies: http://moshez.org
Read the FAQ