[Python-Dev] ++x oddnes

Fredrik Lundh fredrik@pythonware.com
Mon, 13 Aug 2001 18:55:22 +0200

moshe wrote:

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

that was my first implementation (TooStupidCounter).  but
to avoid an endless float vs. integer thread, I decided to post
the plain StupidCounter version instead.

(SlightlyLessStupidCounter is same as StupidCounter,
but returns self.count instead of 0)