Sean Carolan scaro...@gmail.com wrote
The first two lines are redundant you only need the last one.
I should have clarified, the if line.startswith part was used to
break out of the previous for loop, which was used to import the
other, shorter strings.
Thats fair enough if you are doing
Sean Carolan wrote:
if line.startswith('notes'):
break
notes = open('myfile','r').read().split(notes:\n')[1]
The first two lines are redundant you only need the last one.
I should have clarified, the if line.startswith part was used to
break out of the previous for loop, which was used to
I'm not sure how to do this. I'm reading lines in from a text file.
When I reach the string notes:, I want to assign the remainder of
the text file to a single variable (line breaks and all):
text
moretext
moretext
notes:
This is the stuff I want in my variable.
And this line should be included
So right now my code looks something like this:
for line in open('myfile','r'):
if line.startswith('notes'):
## Assign rest of file to variable
Is there an easy way to do this? Or do I need to read the entire file
as a string first and carve it up from there instead?
I ended up
On 4/11/2011 5:14 PM, Sean Carolan wrote:
So right now my code looks something like this:
for line in open('myfile','r'):
if line.startswith('notes'):
## Assign rest of file to variable
Is there an easy way to do this? Or do I need to read the entire file
as a string first and carve
Sean Carolan scaro...@gmail.com wrote
I ended up doing this, but please reply if you have a more elegant
solution:
if line.startswith('notes'):
break
notes = open('myfile','r').read().split(notes:\n')[1]
The first two lines are redundant you only need the last one.
HTH,
Alan G.
if line.startswith('notes'):
break
notes = open('myfile','r').read().split(notes:\n')[1]
The first two lines are redundant you only need the last one.
I should have clarified, the if line.startswith part was used to
break out of the previous for loop, which was used to import the
other,