[Tutor] ints, and long ints?

Magnus Lycka magnus@thinkware.se
Wed, 16 Oct 2002 16:42:45 +0200


At 21:05 2002-10-16 +1300, Thomi Richards wrote:
>awesome, thanks for that...hmmmmmm.... i may have to make this project
>available on 2.2 only :-)

2.2 and up I hope...

That's not a bad choice. I think it's pretty stable by now,
and Python 2.2.x will be along and supported for a long time.
The Python Business Forum and the Snake Farm at Link=F6ping
University will make sure that relevant bugs in 2.3 etc will
be backported to 2.2, and do what they can to make sure that
people who use Python 2.2 won't have to upgrade for at least
two years or so.

Also, Red Hat upgraded to 2.2 with their latest Linux release
(8.0) so I think it's the standard version version on most
relevant platforms. The possibly worrying exception is Jython,
which is still 2.1. From 2.2.2, a bug which was problematic
for Zope and ZODB has been fixed. ZODB works well with 2.2.2
and I think the normal Zope distros will be based on 2.2.2
very soon.

As far as I'm concerned, there is no good reason to stay
with an older python version than 2.2 unless you run
Jython.

In this particular case, if you need to support older
platforms, and don't want to use longs unless they are
needed, you can always use a try block.

Besides, while python 2.2 will do...
 >>> sys.maxint + 1
2147483648L

It will still...

 >>> int('123123123123')
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
ValueError: int() literal too large: 123123123123

So, if you are reading a string from a file or some
kind of user interaction, you might still want

try:
     x =3D int(s)
except ValueError:
     x =3D long(s)

This will work equally well with older versions.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se