473,795 Members | 2,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Subclassing int for a revolving control number

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)

Chris
--
Still searching for an even prime > 2!
Jul 18 '05
13 1517
Stephen Ferg wrote:
I think the simplest solution would be just to use a generator...

*************** *************** ******
def rollover(argMax Number=20):
while True:
for i in range(1, argMaxNumber+1) :
yield i


This can also be spelled as itertools.cycle (xrange(max_num ber)).

--
Ciao,
Matteo
Jul 18 '05 #11
On Tue, 20 Jul 2004, Matteo Dell'Amico wrote:
Stephen Ferg wrote:
I think the simplest solution would be just to use a generator...

*************** *************** ******
def rollover(argMax Number=20):
while True:
for i in range(1, argMaxNumber+1) :
yield i


This can also be spelled as itertools.cycle (xrange(max_num ber)).


Watch out: itertools.cycle doesn't restart the generator when it's
exhausted; instead, it keeps a copy of all the items returned by the
iterator and loops over them.

Jul 18 '05 #12
Personally, rather than all these suggestions of python-written classes or
of itertools.cycle , I would like a C-extension module with something like
this. All it would have to be is an actually C int value with no bounds
checking. This would be usually for working with low-level data, like
bitmaps or compressed data, where you can't have longs and where you need
good performance on simple arithmetic.

Jul 18 '05 #13
On Tue, 20 Jul 2004, Calvin Spealman wrote:
Personally, rather than all these suggestions of python-written classes or
of itertools.cycle , I would like a C-extension module with something like
this. All it would have to be is an actually C int value with no bounds
checking. This would be usually for working with low-level data, like
bitmaps or compressed data, where you can't have longs and where you need
good performance on simple arithmetic.


numarray does this:
from numarray import *
array(254,UInt8 )+4

2

It also greatly speeds up performance on the vector operations needed in
processing bitmaps, etc.

Jul 18 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1558
by: Mizrandir | last post by:
I'd like to subclass numarray's array. I'd like to add some methods and override others like __init__. I don't know how to do this and haven't found help searching the manual or the web, can someone help? For example imagine I just want to do something as simple as making a subclass "NewClass" with the __init__ method overridden so that the behaviour would be: >>> a = NewClass(2) >>> print a
3
1606
by: Emiliano Molina | last post by:
Where can I find information on how to do this? Specifically I am concerned about something like: class NewList(list): def __init__(self): list.__init__(self) The above code does not allow the passing of a sequence to populate the NewList.
2
5163
by: BJörn Lindqvist | last post by:
A problem I have occured recently is that I want to subclass builtin types. Especially subclassing list is very troublesome to me. But I can't find the right syntax to use. Take for example this class which is supposed to be a representation of a genome: class Genome(list): def __init__(self): list.__init__(self) self = ....
3
1698
by: Peter Olsen | last post by:
I want to define a class "point" as a subclass of complex. When I create an instance sample = point(<arglist>) I want "sample" to "be" a complex number, but with its real and imaginary parts computed in point()'s __init__ function with their values based on the arglist. I want to compute with point instances as though they were native complex numbers, but I want to be able to
5
6490
by: Pieter Linden | last post by:
Hi, This question refers sort of to Rebecca Riordan's article on Access web about subclassing entities: http://www.mvps.org/access/tables/tbl0013.htm How practical is this? I am writing a database to track Computer equipment/inventory as well as other devices. Computers, of course, have software installed, so I want to keep track of that. I was
2
1641
by: TheStripe | last post by:
Hello all, Wondering if anyone has come across this problem I am having.. I am Subclassing a RadioButtonList to add some properties that I need. I am building up a table and adding to a placeHolder control. I also register an event handler just before finally adding MyRadioButtonList to a TableCell control.
3
1762
by: Andrius B. | last post by:
Hi all. Could smb provide an Internet site or smth explaining how to use function SetWindowSubclass in vb.net? All examples found by me are in C++ :( Thanks.
5
2337
by: antonyliu2002 | last post by:
I have a Windows console application, which takes around 3 minutes to complete the execution. I am interested in implementing something animate while users are waiting for the process to complete. If you have experience with Linux/Unix, you should be very familiar with the revolving slash ( / ) or the growing dots ( ...... ), which you normally see, when a process is taking some time.
4
1453
by: BiDi | last post by:
I have been trying to subclass complex, but I am not able to get the right-hand arithmetic operators working. As shown below, if an object of my subclass 'xcomplex' is added on the right of a 'comlex' object, the type returned is 'complex', not 'xcomplex'. I've tried subclassing float and it works fine (don't even need to define __coerce__ in that case)
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.