How do loose the /012

Bruce Wolk bawolk at ucdavis.edu
Wed Oct 6 01:03:28 EDT 1999


How about using

string.replace(s,'\n','')

That should remove all returns from the string.  string.strip() only
removes whitespace from the ends.

Bruce

Steve Hunter wrote:
> 
> This code is suppose to take an ascii file made up of sentences and create a
> file in the form of..by example..
> 1 sentence one.
> 2 sentence two
> etc...
> 
> the code is  below and the input/output below that.....appreciate the fix
> that makes
> this work.
> 
> Steve at HOSYS.com
> 
> import string
> 
> file = open('c:\\tmp\\ascii.txt')
> text = file.read()
> sentences = string.split(text,'.')
> 
> newList = []
> cnt = 0
> 
> for s in sentences:
>  cnt = cnt + 1
>  ss = (str(cnt) + ' ' + string.strip(s) + '.' + '\n' )
>  newList.append(ss)
> 
> myfile = open('c:\\tmp\\parsed.txt', 'w')
> myfile.writelines(newList)
> myfile.close()
> file.close()
> 
> input look like:
> AAAA
> AA
> A.
> 
> BBBBBB
> B.
> 
> C.
> 
> DDDD
> DD.
> 
> output looks like
> 1 AAAA
> AA
> A.
> 2 BBBBBB
> B.
> 3 C.
> 4 DDDD
> DD.
> 5 .
> 
> output should look like
> 1 AAAAAAA.
> 2 BBBBBBB.
> 3 C.
> 4 DDDDDD.




More information about the Python-list mailing list