* Flynn, Stephen (L & P - IT) <steve.fl...@capita.co.uk> [2012-07-02 15:03]:
> Tutors,
> 
> Can someone explain to me how I am supposed to make use of readline()
> to grab the next line of a text file please? It may be that I should
> be using some other module, but chose fileinput as I was hoping to
> make the little routine as generic as possible; able to spot short
> lines in tab separated, comma separated, pipe separated, ^~~^
> separated and anything else which my clients feel like sending me.

There are a couple issues that you need to resolve.  For starters, there
is no guarantee that the successive line is actually part of the
preceding line.  It could very well be that the original line is simply
truncated, in which case trying to append the following line would be
incorrect.

What I typically do in a case like this is use a flag variable and pull
the offending line(s).  So, you need to first determine the best course
of action for resolving the inconsistency (eg, how do you verify the
following line belongs with the preceding)?

Try checking the line, if it's less than 13 then flag and store in a
buffer and continue.  The following line _should_ also error, in which
case, you can try to resolve the two lines, or fail out if the criteria
isn't met.  

Essentially, your problem isn't with using fileinput, it's with how you
handle each line that comes in.

-- 
David Rock
da...@graniteweb.com

Attachment: pgpsm5eZpm6mp.pgp
Description: PGP signature

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to