On 08Jun2012 14:36, Neal Becker <ndbeck...@gmail.com> wrote: | If a new file is created by open ('xxx', 'w') | | How can I control the file permission bits? Is my only choice to use chmod | after opening, or use os.open? | | Wouldn't this be a good thing to have as a keyword for open? Too bad what | python calls 'mode' is like what posix open calls 'flags', and what posix open | calls 'mode' is what should go to chmod.
Well, it does honour the umask, and will call the OS open with 0666 mode so you'll get 0666-umask mode bits in the new file (if it is new). Last time I called os.open was to pass a mode of 0 (raceproof lockfile). I would advocate (untested): fd = os.open(...) os.fchmod(fd, new_mode) fp = os.fdopen(fd) If you need to constrain access in a raceless fashion (specificly, no ealy window of _extra_ access) pass a restrictive mode to os.open and open it up with fchmod. Cheers, -- Cameron Simpson <c...@zip.com.au> DoD#743 http://www.cskk.ezoshosting.com/cs/ It was a joke, OK? If we thought it would actually be used, we wouldn't have written it! - Marc Andreessen on the creation of a <blink> tag -- http://mail.python.org/mailman/listinfo/python-list