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
"Sean Carolan" 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 something with
>> 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
"Sean Carolan" 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.
___
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 it
> 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
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