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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4