[Tutor] String Processing Query
Spyros Charonis
s.charonis at gmail.com
Mon May 16 15:51:15 CEST 2011
I have a file with the following contents:
>from header1
abcdefghijkl
mnopqrs
tuvwxyz
*
>from header2
poiuytrewq
lkjhgfdsa
mnbvcxz
*
My string processing code goes as follows:
file1=open('/myfolder/testfile.txt')
scan = file1.readlines()
string1 = ' '
for line in scan:
if line.startswith('>from'):
continue
if line.startswith('*'):
continue
string1.join(line.rstrip('\n'))
This code produces the following output:
'abcdefghijkl'
'mnopqrs'
'tuvwxyz'
'poiuytrewq'
'lkjhgfdsa'
'mnbvcxz'
I would like to know if there is a way to get the following
output instead:
'abcdefghijklmnopqrstuvwxyz'
'poiuytrewqlkjhgfdsamnbvcxz'
I'm basically trying to concatenate the strings
in order to produce 2 separate lines
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110516/04e8cb82/attachment.html>
More information about the Tutor
mailing list