Re: [Tutor] String Processing Query

2011-05-17 Thread Alan Gauld
"Spyros Charonis" wrote 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

Re: [Tutor] String Processing Query

2011-05-17 Thread spawgi
This snipped also works - may be there is a better solution - ', '*'] >>> s = '' >>> for line in lines: line = line.rstrip('\n') if line.startswith('>from header'): continue elif line.startswith('*'): s = s + '\n' else: s = s + line >>> s 'abcdefghijklmnopqrstuvwxyz\npoiuytrewqlkjhgfdsamnbvcxz\

Re: [Tutor] String Processing Query

2011-05-16 Thread James Reynolds
concatenate the entire thing together, including the "*". Once you have that as a single string, use string.split('*') and you will have your two strings. On Mon, May 16, 2011 at 9:51 AM, Spyros Charonis wrote: > I have a file with the following contents: > > >from header1 > abcdefghijkl > mnopq

[Tutor] String Processing Query

2011-05-16 Thread Spyros Charonis
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('>