11-digit integer literal on a 32-bit CPU
Alex
alex at somewhere.round.here
Mon Mar 6 20:11:30 EST 2000
> I need to assign an 11-digit Transaction ID, according to specs I'm
> given by a client.
>
> Begin with 10000000000
> Increment by 1 for each new transaction -- 10000000001, etc.
> (Store as string in a file between transactions)
> As an integer literal, this overflows on an Intel CPU.
> What's a nice trick for dealing with this?
> Total transactions aren't likely to exceed 999,999
Does this do what you want?
class Transaction_ID:
def __init__(self, id_number):
self.number = id_number
def __str__(self):
output = str(self.number)
output = '1' + (10 - len(output)) * '0' + output
return output
def next_id(self):
return Transaction_ID(self.number + 1)
print Transaction_ID(50)
Alex.
More information about the Python-list
mailing list