[Tutor] Working with files
Eve Kotyk
e.kotyk@shaw.ca
Thu, 04 Apr 2002 10:37:16 +0000
--=.WadRJoh?o1nEm0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
How do you open a file, read the file, remove an element in the file and
write it to a backup file.
I can do all of this from the following code from Alan's tutorial except
delete part of the file before rewriting it.
inp = open('menu.txt', 'r')
outp = open('menu.bak', 'w')
for line in inp.readlines():
#here I would like to say that x = "spam'
#if x is in inp.readlines del x
#it seems to me that it doesn't act on the line, it just deletes x. I
can't #figure out any way to have it del x from line and then
write this line. outp.write(line)
inp.close()
outp.close()
E
--
ekotyk
http://members.shaw.ca/e.kotyk/virtualstudio.htm
--=.WadRJoh?o1nEm0
Content-Type: application/pgp-signature
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
iD8DBQE8rCzfyxm8dPG0oMIRAtGgAJ0TrEgsZcwqyOTBbNVkyc3OvGo/2wCfSXWm
HcljW3NNEcXY/onh5aZEalQ=
=rfVY
-----END PGP SIGNATURE-----
--=.WadRJoh?o1nEm0--