[Tutor] file read and write

le dahut le.dahut at laposte.net
Tue Sep 11 10:27:45 CEST 2007


I noticed that it is possible to write this :
"""
file('/tmp/myfile', 'w').write('Hello world\n')
contnt = file('/tmp/sourcefile').read()
"""

instead of :
"""
fh = file('/tmp/myfile', 'w')
fh.write('Hello world\n')
fh.close()

fh = file('/tmp/sourcefile')
contnt = fh.read()
fh.close()
"""

is there a reason not to use the first example ?

K.


More information about the Tutor mailing list