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

François Pinard pinard at iro.umontreal.ca
Thu May 30 10:10:52 EDT 2002


[Delaney, Timothy]

> Why don't we have

> 	while a = file.readline():
> 	    pass

> while we're at it?  After all, it's the same principle - you're trading
> off safety for saving a line or two.

The Python language is oriented towards legibility and clarity, and I
would guess that the above has been rejected as lacking legibility, much
more than for safety considerations.

Doing `lines = open(file).readlines()' looks perfectly safe to me, so I'm
not trading any safety.  The goal of using such writing is not "saving a
line or two", but writing more legibly, by eliminating unnecessary noise.
Saving lines is not very important.  Saving spurious lines is, however.

All those things are quite debatable, there is some aesthetic considerations
associated with legibility; moreover, aesthetics do not alway yield to
legibility.  I think Python is nice because it has _one_ artist in charge,
able to impose a common view.  If it was "democratic", it would loose much.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list