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

Michael P. Soulier msoulier at nortelnetworks.com_.nospam
Wed May 29 15:46:55 EDT 2002


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. 

>>> stuff = "stuff to write"
>>> open('stufffile', "w").write(stuff)
>>> open('stufffile', "r").read()
'stuff to write'

    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