[Tutor] Import multiple lines of text into a variable

Sean Carolan scarolan at gmail.com
Mon Apr 11 23:14:26 CEST 2011

> 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 doing this, but please reply if you have a more elegant solution:

if line.startswith('notes'):
notes = open('myfile','r').read().split(notes:\n')[1]

More information about the Tutor mailing list