Re: [Tutor] Import multiple lines of text into a variable

2011-04-12 Thread Steven D'Aprano
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

Re: [Tutor] Import multiple lines of text into a variable

2011-04-12 Thread Alan Gauld
"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

Re: [Tutor] Import multiple lines of text into a variable

2011-04-11 Thread Sean Carolan
>> 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

Re: [Tutor] Import multiple lines of text into a variable

2011-04-11 Thread Alan Gauld
"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. ___

Re: [Tutor] Import multiple lines of text into a variable

2011-04-11 Thread bob gailer
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

Re: [Tutor] Import multiple lines of text into a variable

2011-04-11 Thread Sean Carolan
> 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

[Tutor] Import multiple lines of text into a variable

2011-04-11 Thread Sean Carolan
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