int() and leading zeros in Python 2.6

P

Pete Forman

I'm holding off installing Python 2.6, waiting for some packages to
become available for it. I wonder if someone could tell me the best
way to avoid future problems parsing decimal integers with leading
zeros.
9

That works in 2.5 but will break in 2.6 AFAIK as int() is being
changed to use Numeric Literal syntax. It will give a syntax error as
the leading 0 will force an octal radix and the 9 will be out of
range. Will this avoid the breakage?
9

Or should I use this uglier variation that needs 2.2.2 or later?
9

Is the documentation for int([x[, radix]]) correct? I'd say that the
default for radix has become 0.

http://docs.python.org/library/functions.html#int
 
P

Peter Otten

Pete said:
I'm holding off installing Python 2.6, waiting for some packages to
become available for it. I wonder if someone could tell me the best
way to avoid future problems parsing decimal integers with leading
zeros.

You can have multiple versions of python simultaneously.

This works for 2.x and 3.0.

2.6 will accept two prefixes "0o" and "0" when you give 0 as the radix
argument. 3.0 will only accept "0o" and raise a ValueError for "0". None of
this affects you.
That works in 2.5 but will break in 2.6 AFAIK as int() is being
changed to use Numeric Literal syntax. It will give a syntax error as
the leading 0 will force an octal radix and the 9 will be out of
range. Will this avoid the breakage?

9

That's unnecessary.
Or should I use this uglier variation that needs 2.2.2 or later?

9

And that's cargo cult code.
Is the documentation for int([x[, radix]]) correct?
Yes.

I'd say that the default for radix has become 0.

You can say that, but you're wrong.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top