[Python-Dev] Can't open standard streams with "a"

Skip Montanaro skip.montanaro at gmail.com
Fri Apr 6 12:06:11 EDT 2018


In Python 2 you can open the standard output and error streams in
append mode, despite the fact that they aren't technically seekable.
This changed somewhere along the way in (I think) io.open. There's an
open bug report about this:

https://bugs.python.org/issue27805

I just stumbled on it porting an application from Py2 to Py3 where my
default logfile is /dev/stderr. I don't ever want to truncate a user's
logfile, so "a" is a nice default, but in case the user doesn't name a
logfile, I have to test, just in case /dev/stderr is the candidate.
This seems error-prone, and must be done in all applications. The Py2
behavior seems less error-prone. I know explicit is better than
implicit, but practicality also beats purity. Also, os.open is fine
with O_APPEND on these streams.

Any chance of this getting into 3.7 or will a fix have to wait for 3.8
at this point? (I'm guessing "no" as I don't see a patch.)

Skip


More information about the Python-Dev mailing list