This question has to do with the answer to Write file with specific permissions in Python for opening a file for writing (in python) with specific permissions.
The code in the answer looks like:
with os.fdopen(os.open('foo', os.O_APPEND | os.O_CREAT, 0o644)) as out:
out.write("hello\n")
This code in 2.7.1 (my company does not have 2.7.3 installed) produces:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
IOError: File not open for writing
os.fdopen
has its own mode argument, but setting that doesn't help:
>>> with os.fdopen(os.open('foo', os.O_APPEND | os.O_CREAT, 0o644), 'a') as out:
... out.write("hello\n")
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 22] Invalid argument
Long story short, I have not been able to figure out how to actually write to a file that has been opened via os.fdopen
and os.open
. Any ideas? Known bug in 2.7.1?
Thanks in advance!
O_APPEND | O_WRONLY
toos.open
? – Fred Foo