[issue12760] Add create mode to open()

2012-01-11 Thread David Townshend
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

[issue12760] Add create mode to open()

2011-11-06 Thread David Townshend
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

[issue12760] Add create mode to open()

2011-10-31 Thread David Townshend
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

[issue12760] Add create mode to open()

2011-08-18 Thread David Townshend
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

[issue12760] Add create mode to open()

2011-08-18 Thread David Townshend
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. --

[issue12760] Add create mode to open()

2011-08-18 Thread David Townshend
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

[issue12760] Add create mode to open()

2011-08-16 Thread David Townshend
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.

[issue12760] Add create mode to open()

2011-08-16 Thread David Townshend
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

[issue12741] Add function similar to shutil.move that does not overwrite

2011-08-13 Thread David Townshend
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

[issue12741] Implementation of shutil.move

2011-08-12 Thread David Townshend
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