[Tutor] Import multiple lines of text into a variable
Sean Carolan
scarolan at gmail.com
Mon Apr 11 23:05:40 CEST 2011
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 too.
Also this one.
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?
More information about the Tutor
mailing list