[issue12762] EnvironmentError_str contributes to unportable code
Jakub Wilk
report at bugs.python.org
Tue Aug 16 19:09:06 CEST 2011
New submission from Jakub Wilk <jwilk at jwilk.net>:
It is a surprisingly common error in 3rd party code to write something like this:
try:
eggs()
except OSError, e:
if e.errno == 17:
ham()
This is wrong, because according to POSIX[0], “only […] symbolic names should be used in programs, since the actual value of the error number is unspecified.”
I was wondering why Python programmers keep writing such unportable code - e.g. I've never seen C code that would compare errno variable with a hardcoded integer. I came into conclution that the Python interpreter itself is (partially) to blame. Currently exception message generated from errno looks like this:
"[Errno 2] No such file or directory: '/punt'"
It would be better if the message was:
"[ENOENT] No such file or directory: '/punt'"
or, if the above is too hard to implement, even:
"No such file or directory: '/punt'"
----------
messages: 142207
nosy: jwilk
priority: normal
severity: normal
status: open
title: EnvironmentError_str contributes to unportable code
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12762>
_______________________________________
More information about the Python-bugs-list
mailing list