Write file with specific permissions in Python -
i'm trying create file user-readable , -writable (0600).
is way using os.open() follows?
import os fd = os.open('/path/to/file', os.o_wronly, 0o600) myfileobject = os.fdopen(fd) myfileobject.write(...) myfileobject.close() ideally, i'd able use with keyword can close object automatically. there better way i'm doing above?
what's problem? file.close() close file though open os.open().
with os.fdopen(os.open('/path/to/file', os.o_wronly | os.o_creat, 0o600), 'w') handle: handle.write(...)
Comments
Post a Comment