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

Michael P. Soulier msoulier at nortelnetworks.com_.nospam
Thu May 30 14:43:16 EDT 2002


On Wed, 29 May 2002 21:02:21 +0000 (UTC), Huaiyu Zhu
<huaiyu at gauss.almadan.ibm.com> wrote:
>>> 
>>>>>> stuff = "stuff to write"
>>>>>> open('stufffile', "w").write(stuff)
>>>>>> open('stufffile', "r").read()
>>> 'stuff to write'
>>> 
>>
>>yes, but can you disagree with the statement that it is bad programming
>>practice.  I sure can't.
> 
> For what reason is it bad?  

    Well, as one of the credos of Python is that explicit is better than
implicit, why are we relying on the implicit nature of file objects to close
themselves? It's not nearly as easy to read.
    Then again, list comprehensions seem somewhat cryptic for Python as well.

    Mike

-- 
Michael P. Soulier, QX41, SKY  Tel: 613-765-4699 (ESN: 39-54699)
Optical Networks, Nortel Networks, SDE Pegasus
"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort."  -Harley Hahn, A Student's Guide to Unix



More information about the Python-list mailing list