[Tutor] Readability, in general: was Re: Reading only a few specific lines of a file

Marilyn Davis marilyn at deliberate.com
Fri May 23 19:30:47 CEST 2008


On Fri, May 23, 2008 10:06 am, Alan Gauld wrote:

> "Marilyn Davis" <marilyn at deliberate.com> wrote
>
>
>> (I'm sorry for the duplicate, Alan.)
>>
>
> I didn't see a duplicate! ;-)
>
>
>>> linecount = 0 for line in file("itemconfig.txt", 'rU'): if line ==
>>> objectToLoad or linecount > 0: if linecount == 0: linecount = 5
>>> itemList.append(line.split()[:5])
>>> linecount -= 1
>>
>> I always go for readability.  So I like "for x in range(5):" to go 5
>> times.  I'm not sure what we should be doing 5 times either.
>
> You could use a nested for loop but that would involve the use
> of an iterator.next() function which I didn't want to confuse the issue
> with, although John has pointed it out now anyway. Since the outer for
> loop is doing the next() call for us it didn't seem necessary.
>
>> Similarly, for readability, I choose the if/elif/else form of switch
>> replacement.
>
> Are you referring to the other thread?
> There is no switch here.
>
>
>> Also, I don't like to see the obfuscated forms of the conditional
>> operator.  Heck, I'm not even crazy about the Python conditional in 2.5.
>>
>
> Similarly there is no conditional statements here? Again are
> you refering to the other recent thread?

Yes, I am referring to other threads.  I have time, right now, to read and
learn.

Maybe I should have said the same thing in each thread.  I'm sorry.

Marilyn

>
>> I like to say "The point of a programming language is to communicate
>> with other engineers (in a language that also the computer understands)."
>>
>
> I agree. :-)
>
>
> Alan G.
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor





More information about the Tutor mailing list