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

Guido van Rossum guido at python.org
Wed Aug 17 03:13:22 CEST 2011


On Tue, Aug 16, 2011 at 5:12 PM, Bruce Leban <bruce at leapyear.org> wrote:
>
> On Tue, Aug 16, 2011 at 4:46 PM, Guido van Rossum <guido at python.org> wrote:
>>
>> So what's the use case? In general when using a command line
>> environment overwriting the file is what you *want* to happen. Like
>> with Unix "foo >bar". I don't even think there *is* a shell syntax for
>> not overwriting an existing file, though you can use >> to append
>> instead of overwrite -- this is open(filename, 'a').
>
> We weren't just discussing command line tools.

Well if anything, Python is *lower* level than command line tools, not higher.

> That said, I'm sure I'm not
> the only person on this list who has inadvertently overwritten a file using
> foo > bar. While we may have grown accustomed to this behavior and some
> people (like you) may even consider it desirable, not everyone does.

But are they right?

>> > I've had enough working with programs that do things like silently eat
>> > exceptions and I consider silently overwriting a file in the same class.
>>
>> Always? How would you update an existing file if you can't overwrite
>> files?
>
> I didn't say never overwrite. What I don't like is programs overwriting
> files without explicitly intending to do that.

Ah, but when you write open(fn, 'w') you *do* explicitly intend to
overwrite. That's what it does.

> Yes, there's a long legacy of overwriting files without warning or intent. I
> suppose I'm fighting an uphill battle (and it's not my highest priority
> complaint about bad code for that matter).

Right.

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



More information about the Python-ideas mailing list