[Tutor] write to a file

Scot W. Stevenson scot@possum.in-berlin.de
Tue, 20 Aug 2002 14:42:39 +0200


Hello Gus, 

> file = file('C:\filename.txt', 'w')
> x = 'hello, sir'
> file.write(x)

In think your supposted to close the file after you're done, too, tho 
nothing evil seems to happen if you don't (or maybe it is all the Garlic 
hanging from my monitor). So we'd have:

filename = file('myfile.txt', 'w')
filename.write('Write this string to file')
filename.close()

While we're here: Is there any possible problem hat could arise from giving 
a variable ('file' in this case) the same name as a function ('file', the 
function formerly know as 'open') ?

Y, Scot

-- 
  Scot W. Stevenson wrote me on Tuesday, 20. Aug 2002 in Zepernick, Germany   
       on his happy little Linux system that has been up for 1524 hours       
        and has a CPU that is falling asleep at a system load of 0.00.