David Townshend added the comment:
I've done a bit or rewording in the io docs, but I honestly don't know if this
is any better that what you already had!
--
Added file: http://bugs.python.org/file24210/x_diff2.patch
___
Python trac
David Townshend added the comment:
It is already possible to write a wrapper function that does it:
def create(file):
fd = os.open(file, os.O_EXCL | os.O_CREAT | os.O_WRONLY)
return os.fdopen(fd)
The point it not that it can't be done, but that it is not straight forward.
The
David Townshend added the comment:
I see this has been marked as a duplicate of http://bugs.python.org/issue12797.
Please explain how this is, since that proposal does not appear to provide the
functionality discussed here.
--
___
Python tracker
David Townshend added the comment:
I hope this patch suits you better :-)
I've updated the documentation typo (thanks for pointing that out). I've also
changed 'c' to 'x', since I think that if there is a convention we should stick
to it. I don't think th
David Townshend added the comment:
Changing form 'c' to 'x' is easy enough, and if there is already a convention
it makes sense to stick to it.
I thought I had done a mercurial diff! I'll try again and resubmit.
--
David Townshend added the comment:
My aim isn't to add all the commonly used flags, that would be pointless since
its already possible using os.open. The aim is to add a missing feature to the
builtin open(), i.e. file creation. At the moment open() implements read,
write, and append
David Townshend added the comment:
It was discussed on python-ideas, but the subject of the thread was actually on
shutils.move so it was not really discussed much. I will repost this idea
separately.
--
___
Python tracker
<http://bugs.python.
New submission from David Townshend :
Currently, opening a file with open(file, 'w') overwrites existing files. It
would be useful for open() to raise an error when the file exists. This
proposal is to add a 'c' mode to open, which has the effect to creating a file
David Townshend added the comment:
A bit of research has shown that the proposed implementation will not work
either, so my next suggestion is something along the lines of
def move2(src, dst):
try:
os.link(src, dst)
except OSError as err:
# handle error appropriately
New submission from David Townshend :
The shutil.move function uses os.rename to move files on the same file system.
On unix, this function will overwrite an existing destination, so the obvious
approach is
if not os.path.exists(dst):
shutil.move(src, dst)
But this could result in race
10 matches
Mail list logo