[Python-ideas] Add create mode to open()
David Townshend
aquavitae69 at gmail.com
Thu Aug 18 07:54:32 CEST 2011
>
> Perhaps we need a HOW-TO on working with files that discusses special-case
> needs and solutions that use os, tempfile, etc alternatives to builtin open.
>
Not a bad idea, but would it not get too complicated? Starting with ways to
use os.open is fine, but to do it properly we would need to go on to copying
and moving, and this would involve basically rewriting the implementation of
shutils into the HOW-TO. I think that this is a good idea, but not enough
on its own.
My suggestion, to do this properly, would be to first implement the open
create mode in open. Then update (or write new) copy functions (i.e.
copyfile, copy2, copytree) to use the create mode, thereby effectively
changing the linux shell commands represented from "cp" to "cp -n". Finally
implement a new move function which, if possible, uses link/unlink or the
immutable attribute (as discussed in the tread on shutil.move), and falls
back to copy/unlink using the new copytree. The resulting functions would
correspond to the "no-clobber" versions of the equivalent shell commands.
The only problem is that O_EXCL may not be supported on all platforms. Can
anyone tell me which platforms these are? I would like to see if I can find
a way to achieve the same effect on those platforms, but so far I haven't
been able to find out what they are.
A HOW-TO would be useful to discuss other methods, such as tempfile, which
will be a lot easier to use with the no-clobber versions.
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110818/98b063d5/attachment.html>
More information about the Python-ideas
mailing list