Subclassing int for a revolving control number

Antoon Pardon apardon at forel.vub.ac.be
Mon Jul 19 09:54:18 EDT 2004


Op 2004-07-16, Dan Sommers schreef <me at privacy.net>:
> On Fri, 16 Jul 2004 16:08:28 -0400,
> Chris Cioffi <evenprimes at gmail.com> wrote:
>
>> Hello all!
>> I'm trying to subclass int such that once it reaches a certain value,
>> it flips back to the starting count.  This is for use as an X12
>> control number.  Subclassing int and getting the display like I want
>> it was trivial, however what's the best way to make it such that:
>> 990 + 1 = 991 
>> 991 + 1 = 992
>> ...
>> 998 + 1 = 999
>> 999 + 1 = 001
>
>> Should I set any of the special functions like __sub__ to raise
>> NotImpemented and just make my own custom assignment and __add__
>> functions?  (The other fucntions would make no sense in this
>> context...)
>
>> Is there an "on change" kind of meta-function?  (Like the onChange
>> event in a GUI text control)
>
> That all sounds like overkill, at least to my old-fashioned, minimalist
> tastes.  Remember, too, that Python has a "we're all adults" philosophy.

Sorry, but remarks like the one that follows, let me doubt that.

from http://docs.python.org/api/threads.html:

|  To prevent naive misuse, you must write your own C extension to call
|  this.

-- 
Antoon Pardon



More information about the Python-list mailing list