[CentralOH] 2013-04-11 道場

Kurtis Mullins kurtis.mullins at gmail.com
Fri Apr 12 16:38:24 CEST 2013


Wouldn't it be more correct to do this?

if f.readline():
    # Do something
else:
    break

Reasoning:
1. It's more likely that each line will have data; therefore, make that the
first (priority) condition
2. Logically thinking, you assume your file has data. You only break in the
case that it doesn't have data, which is probably going to be last (EOF).
So the procedural code would be organized accordingly.

Just my $0.02.

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 :) So my apologies if
this is the wrong place for that discussion.

Thanks!
- Kurtis


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

> f = open('foo', 'rU')
> while True:
>     ...
>     # if f.readline() == '': # bad style
>     # if not len(f.readline()): # bad style
>     # if len(f.readline()) == 0: # bad style
>     if not f.readline():
>         break
>
> https://www.coursera.org/course/programming1
>
> http://en.wikipedia.org/wiki/Magic_Software_Enterprises
>
> http://www.python.org/dev/peps/pep-0008/
> Yes:
>     if not seq:
>     if seq:
> No:
>     if len(seq):
>     if not len(seq):
> no:
>     if seq == '':
>
> CSV module is great
> http://docs.python.org/2/library/csv.
> http://pymotw.com/2/csv/
> http://www.python.org/dev/peps/pep-0278/
>
> http://pymotw.com/2/contents.html
>
> file.readline() returns empty string at EOF.
>
> https://en.wikipedia.org/wiki/The_New_New_Thing
> https://en.wikipedia.org/wiki/James_H._Clark
>
> better keyboards
> Model M13 Trackpoint II
> https://en.wikipedia.org/wiki/Model_M_keyboard
> https://en.wikipedia.org/wiki/Unicomp
> http://pckeyboard.com/page/category/EnduraPro
> https://en.wikipedia.org/wiki/ZF_Electronics#Cherry_switches
> https://en.wikipedia.org/wiki/Pointing_stick
> https://en.wikipedia.org/wiki/Happy_Hacking_Keyboard
>
> has bad feel:
> https://en.wikipedia.org/wiki/Optimus_Maximus_keyboard
>
> https://en.wikipedia.org/wiki/Sassafras
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> http://mail.python.org/mailman/listinfo/centraloh
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20130412/237aa0c9/attachment.html>


More information about the CentralOH mailing list