[CentralOH] 2013-04-11 道場

jep200404 at columbus.rr.com jep200404 at columbus.rr.com
Fri Apr 12 22:51:13 CEST 2013

On Fri, 12 Apr 2013 10:38:24 -0400, Kurtis Mullins <kurtis.mullins at gmail.com> wrote:

> Wouldn't it be more correct to do this?
> if f.readline():
>     # Do something
> else:
>     break

That depends on what is in the "...". 
In this case, it was desired to _ignore_ a line at the end 
of the loop or bail out of the loop when there is no more input. 
The "..." had highly naive, deliberately unoptimized code for
some task in a Toronto Python class on coursera. The "..." code 
was something vaguely like: 

    name = f.readline().strip()
    rating = f.readline().strip()
    price = f.readline().strip()
    cuisine = f.readline().strip()

Of course, that just leads to more questions about the 
larger context, to which I refer you to the class. 
There was discussion about the wisdom of the input format, 
but for the sake of the course, the input format was a fait 
accompli, kind of like maintaining other peoples' code in the 
real world. 

XY wrote a much shorter, somewhat "functional" approach 
using .read(), zip(), dict(), list comprehensions and friends. 
There was discussion of the strengths and drawbacks of XY's code 
and mine. 

> On Fri, Apr 12, 2013 at 10:16 AM, <jep200404 at columbus.rr.com> wrote:

> Judging by the other information you have in this email, I'm assuming this
> was just an over-view from a meeting you guys had :) 

You're being generous. 

> So my apologies if this is the wrong place for that discussion.

This is a good place for that discussion. It'd be fun for XY 
to show what he remembers of his code, then see who can beat it. 
It'd also be fun to see who can write code that is clearer and 
more naive than what I wrote. 

More information about the CentralOH mailing list