Python Gotcha with Octal Numbers

Fredrik Lundh fredrik at pythonware.com
Wed Feb 13 17:20:50 EST 2002


John Machin wrote:
> Yes, unfortunately there is a lot of octal in the library. Some of it
> has the reasonable excuse of copying existing Unix practice or
> mechanical translation of existing C code:
>
> stat.py:    return mode & 0170000
> stat.py:S_IFDIR  = 0040000

fixing the library would be trivial.

encouraging people to fix their code would also be trivial
(add both spellings, use the warning system to phase out
the old spelling).

code that expects eval(str) not to blow up on things read
from configuration files, things in data files, things received
over the network (yeah, I know about security), etc, is a
bit more difficult to deal with.

Traceback (most recent call last):
  File "effbot.py", line 105, in ?
  File "SimpleXMLWriter.py", line 103, in end
    assert self.__tags, "unbalanced end(%s)" % tag
AssertionError: unbalanced end(F)





More information about the Python-list mailing list