[Zope-Coders] int() returns long in Py2.3.2?
Shane Hathaway
shane at zope.com
Wed Nov 5 00:49:53 EST 2003
On 11/04/03 17:33, Fred L. Drake, Jr. wrote:
> Chris McDonough writes:
> > I'm not sure if this is a bug or a feature in Python 2.3.2, but code
> > that calls int() with an argument that is a number > sys.maxint no
> > longer throws an OverflowError as it did in 2.1, 2.2, et. al.
>
> This is not a bug. Think "integer", not "N-bits", and it makes sense
> that they're all one big happy family.
... except when you want to talk to other languages, particularly C.
Sometimes it's important to check the range of an integer before passing
it to C code. For example, time.localtime(2**31-1) returns a 2038 date,
while time.localtime(2**31) returns a 1901 date. (2038 is going to be
an interesting year--maybe that's the year Guido will get his time machine!)
int() used to be the way to check the range of an integer. Perhaps a
better way is struct.pack("i", n). (n > sys.maxint only checks the
positive limit, not the negative limit.)
Shane
More information about the Zope-Coders
mailing list