I expected that to be handled by the C library, and in C there is no error:
$ cat open_stderr_in_appendmode.c
#include <stdio.h>
main()
{
FILE * stderr = fopen("/dev/stderr", "a");
if (stderr == 0)
{
printf("failed\n");
}
else
{
printf("succeded\n");
fprintf(stderr, "\nthis goes to stderr\n");
fclose(stderr);
}
}
$ gcc open_stderr_in_appendmode.c
$ ./a.out
succeded
this goes to stderr
The same goes for Py2's built-in and codecs.open():
$ python
Python 2.7.6 (default, Nov 23 2017, 15:49:48)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import codecs
>>> import io
>>> with open("/dev/stderr", "a") as f: f.write("works\n")
...
works
>>> with codecs.open("/dev/stderr", "a") as f: f.write("works\n")
...
works
>>> with io.open("/dev/stderr", "a") as f: f.write("works\n")
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 29] Illegal seek
>>>
So io.open() really seems to do its own thing, and differently.