I'm trying to create a file that is only user-readable and -writable (0600
).
Is the only way to do so by using os.open()
as follows?
import os
fd = os.open('/path/to/file', os.O_WRONLY, 0o600)
myFileObject = os.fdopen(fd)
myFileObject.write(...)
myFileObject.close()
Ideally, I'd like to be able to use the with
keyword so I can close the object automatically. Is there a better way to do what I'm doing above?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…