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

Donn Cave donn at u.washington.edu
Wed May 29 16:44:16 EDT 2002


Quoth "Michael P. Soulier" <msoulier at nortelnetworks.com_.nospam>:
| On 24 May 2002 07:53:38 GMT, Markus Demleitner
| <msdemlei at tucana.cl.uni-heidelberg.de> wrote:
|> 
|> The Jython docs state that
|> open("some.name", "w").write(stuff)
|> is bad programming practice (and indeed claim that in Jython,
|> the above construct leaves some.name empty).
|
|     I can't speak for Jython, but in CPython 2.1, it works fine. 

Yes, of course.  The problem is that Java doesn't support the timely
finalization we enjoy in C Python, so for the Java implemention you
have to explicitly invoke the close() that would implicitly be done
during finalization.  That causes the buffer to be flushed to the
actual disk file.  I assume finalization will eventually occur in
any case, if only at program exit, so this would only be an issue
if the file is needed before then.

I bet this has already been said, if so my apologies for the waste
of bandwidth.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list