[Tutor] newbie question-saving changes to file thanks and another question

Ron Nixon nixonron@yahoo.com
Wed Mar 5 14:21:02 2003


--0-1403441201-1046892017=:26924
Content-Type: text/plain; charset=us-ascii


Thanks to all who helped with the saving changes to a file. One additional question, if I want to go through and say change five or six things would I use search and then  IF, ELSE ? and what would it look like. something like the code below? is this correct?

infile = open('c:/address.txt')
s = infile.read()
IF s.search(s, 'ROAD')
s=s.replace('ROAD', 'RD')
IF s.search(s,'STREET')
s =s.replace('STREET', 'ST')
out_file = open("c:/address.txt", "w")
out_file.write(s)
out_file.close()


 



---------------------------------
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, and more
--0-1403441201-1046892017=:26924
Content-Type: text/html; charset=us-ascii

<P>Thanks to all who helped with the saving changes to a file. One additional question, if I want to go through and say change five or six things would I use&nbsp;search and then &nbsp;IF, ELSE ? and what would it look like. something like the code below? is this correct?</P>
<P>infile = open('c:/address.txt')<BR>s = infile.read()<BR>IF s.search(s, 'ROAD')<BR>s=s.replace('ROAD', 'RD')<BR>IF s.search(s,'STREET')<BR>s =s.replace('STREET', 'ST')<BR>out_file = open("c:/address.txt", "w")<BR>out_file.write(s)<BR>out_file.close()<BR></P>
<P>&nbsp;</P><p><br><hr size=1>Do you Yahoo!?<br>
<a href="http://rd.yahoo.com/finance/mailtagline/*http://taxes.yahoo.com/">Yahoo! Tax Center</a> - forms, calculators, tips, and more
--0-1403441201-1046892017=:26924--