[Tutor] Readlines

Adam Vardy Adam Vardy <anvardy@roadrunner.nf.net>
Wed Jun 25 14:56:50 2003


Tuesday, June 24, 2003, 6:01:33 PM, you wrote:

>> >> for line in f.xreadlines():
>> >>     print line
>> 
>> How do you tell what line it is on there?

>> You cant, not unless you create and increent your 
>> own counter:

>> lineCount = 0
>> for line in f.xreadlines():
>>     print lineCount, line
>>     lineCount += 1

Yep. What you start with seems like the more aesthetic, Pythonic type
form. And its rather nicer to keep the plain English interpretation of
just the two lines. What I'm saying is, well most languages have this
FOR command, and they all generally use it to count sequentially, with
some options sometimes.

So it would be neater if Python kept to that tradition. And had an implied
counter for any structure like that, without having to declare a variable
counter, like it was a low level kind of language.

I was thinking you could probably access the counter out of
>> for line in f.xreadlines():
>>     print line

Since, to do what you're asking of it, it has to be keeping track with
exactly this kind of integer counter.

When you have to add extra variables, it just adds more text on your
screen, and less space to review the main stuff you've actually
written.


-- 
Adam Vardy