[Python-ideas] Add create mode to open()

Benjamin Peterson benjamin at python.org
Wed Aug 17 05:49:04 CEST 2011


Devin Jeanpierre <jeanpierreda at ...> writes:
> 
> LBYL is impossible here without a race condition, in fact, because the
> situation can change between looking and leaping. An exception, or
> else return code, is the only way. These can be checked for after the
> fact.

How often in this used? In every application I've written, writing a file
usually results from the user giving a path, in which case it's intended to
replace whatever is already there.

> 
> I'd also point out that for those that don't want race conditions,
> Python is discouraging. The correct incantation involves two
> undocumented constants, plus a unique and rarely used way of opening
> files that involves unix file descriptors.

If you truly want to avoid all filesystem race conditions, you're going to be
dealing with file descriptors and low-level syscalls galore. Moving one aspect
to a higher level is not too helpful on the whole.







More information about the Python-ideas mailing list