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

John La Rooy larooy at xtar.co.nz
Fri May 31 06:55:04 EDT 2002


On 30 May 2002 18:43:16 GMT
"Michael P. Soulier" <msoulier at nortelnetworks.com_.nospam> wrote:

> 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.
> 

Do you explicitly del all your objects too, or wait for them to disappear when they go out of scope?

John



More information about the Python-list mailing list