[Tutor] Line continuation with readlines

2005-10-05 Thread Craig MacFarlane

Hello,

Is there a way to make line continuation work with
the readlines function?

i.e.

  this is \
one line.

Thank you,
Craig




__ 
Yahoo! for Good 
Donate to the Hurricane Katrina relief effort. 
http://store.yahoo.com/redcross-donate3/ 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Line continuation with readlines

2005-10-05 Thread Danny Yoo


On Mon, 3 Oct 2005, Craig MacFarlane wrote:

 Is there a way to make line continuation work with
 the readlines function?

 i.e.

   this is \
 one line.

Hi Craig,

readline() doesn't look at the content of lines, so no, not out of the
box.  However, would it be satisfactory if you wrote a function to define
that behavior?


Good luck to you!

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Line continuation with readlines

2005-10-05 Thread bob
At 07:20 PM 10/3/2005, Craig MacFarlane wrote:
Hello,

Is there a way to make line continuation work with
the readlines function?

i.e.

Do you mean e.g.?

   this is \
 one line.

I assume the above is a 2 line file you wish to read using a file object's 
readlines method. There is nothing native to help you. I suggest you use 
the read method, then remove any sequence of \ followed by \n then split at \n.

input = file('c:/foo.txt').read()
input2 = input.replace('\\\n', '')
input3 = input2.split('\n')

Now you have a list of logical lines. Note there are no \n at the end. 
readlines leaves the \n at the end of the lines. 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor