[Tutor] newbie search and replace

Gregor Lingl glingl@aon.at
Mon Jan 27 15:13:02 2003


Ron Nixon schrieb:

> I have a file with several thousand address in it with different 
> spellings of "st", "street" "road", "rd" "lane", "ln"
>
> I want to go in a standardize all the spellings. The file looks like 
> this below
>
>  
>
> 100 Broad Street
>
> 50 Apple LN
>
> 24 Dirckson St.
>
> 439 Bullock RD
>
> 342 Nash Road
>
> I tried something like this
>
> addr = open('c://address.txt')
>
> import string
> addr = open('c://address.txt')
> addrN = addr.readlines()
> addrN.replace('LN', 'Lane')
>
> I got an error message back. Can someone tell me what am I doing wrong 
> here and how to correct the problem to get the results I want?
>
>  
>
The readlines() method outputs a list of strings, whereas replace() is a 
string-method.
If you used addr.read() instead, which reads in the content of the file 
as a string, the
replace()-method should work.


HTH; Gregor


> Ron
>
>
> ------------------------------------------------------------------------
> Do you Yahoo!?
> Yahoo! Mail Plus 
> <http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com> - 
> Powerful. Affordable. Sign up now 
> <http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com>