Octal number problem

Steven Taschuk staschuk at telusplanet.net
Thu Feb 20 08:22:49 CET 2003

Quoth Carlos Ribeiro:
> On Wednesday 19 February 2003 23:34, Chad Netzer wrote:
> > yes; eval("010") == 8
> >
> > however,
> >
> > int("010") = 10
> I may be mistaken (and someone probably will be more than happy to tell me 
> why), but this inconsistence alone seems like a good reason to deprecate 
> octals (if only in Python 3000!). It really makes no sense to have 
> eval("010") != int("010").

Well, it makes sense to me, for whatever that's worth.

A user-typed string probably demands the decimal interpretation,
because users generally don't know any other base.  Likewise for
human-readable data formats which might have prepended zeroes for,
say, sorting purposes.

For the programmer who's doing bit manipulations, however, octal
and hex notations are very useful.  For example,
	x & 0x0ff0
obviously extracts eight contiguous bits from x, while the decimal
	x & 4080
is somewhat mysterious.  (For a real-life case, consider a UTF-8

So, having the parser do something different than int() makes
sense; they have different audiences, with different needs.

Steven Taschuk             "The world will end if you get this wrong."
staschuk at telusplanet.net    (Brian Kernighan and Lorrinda Cherry,
                            "Typesetting Mathematics -- User's Guide")

More information about the Python-list mailing list