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

Guido van Rossum guido at python.org
Wed Aug 17 00:43:57 CEST 2011


On Tue, Aug 16, 2011 at 2:26 PM, Benjamin Peterson <benjamin at python.org> wrote:
> David Townshend <aquavitae69 at ...> writes:
>
>>
>>
>> This idea was proposed in the discussion on shutil.move, but I thought it
> would be worth posting separately to avoid confusing the discussion.
>>
>> The idea is to add a create mode ('c') to the builtin open() function, which
> will have the same effect as os.open(file, os.O_EXCL|os.O_CREAT).  I have added
> an issue (http://bugs.python.org/issue12760) for this, including a patch.
>
> I am -1 because
>
> - Possibly not portable or at least subject to implementations of
> varying quality.
> - No precedence in other languages or fopen() for that matter.
> - It's not hard to use os.fdopen().

Agreed. Also I think that in most cases the right thing to do is to
quietly overwrite the file. If you're implementing a UI where you want
look-before-you-leap, the app should code an explicit test so it can
issue a proper error message (the exception will not be fun for the
user :-).

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list