How do loose the /012

Steve Hunter Steve at HOSYS.com
Tue Oct 5 16:11:51 EDT 1999


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