Why no open(f, "w").write()?

Donn Cave donn at u.washington.edu
Wed May 29 19:48:24 EDT 2002


Quoth Gary Herron <gherron at islandtraining.com>:
...
| Thus the "bad" part of this programming practice is that the timing of
| the implied close is dependent Python implementation issues (i.e.,
| the timing of the garbage collection), and such dependencies are never
| a good thing to rely on.

The confusing thing about this practice is that it's both
good and bad.

I wouldn't say open(n, m).write(v) is worth defending per se,
but the notion that the system can tell an object when its
lifetime is over is very valuable in general, in an object
oriented programming model.  In more complicated usage, where
the file object (or window, or whatever) persists for some
time and may have several references in use, I'm with M Pinard,
it would seem like a potentially good programming practice.

It's too bad things like good programming practice have to be
subject to the limitations of other programming languages.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list