PEP 308: some candidate uses cases from live code

Cameron Laird claird at lairds.com
Mon Feb 10 08:17:07 EST 2003


In article <mailman.1044781086.26704.python-list at python.org>,
Tim Peters <tim_one at email.msn.com> wrote:
>[Martin Maney]
>> ...
>> Candidate 3 - calculate "school year" from year & month
>>
>>         if d0.month < 7:
>>             sy = d0.year - 1
>>         else:
>>             sy = d0.year
>>
>>     Becomes, after a little rearrangement:
>>
>>         sy = d0.year - (1 if d0.month < 7 else 0)
>>
>>     I think this actually expresses the original logic a little more
>>     clearly: the school year is the day's year unless the day's month is
>>     January through June; then one must be subtracted to get the calendar
>>     year during which the school year began.
>
>Me too, but note that it could be written (even in Python 1.0):
>
>    sy = d0.year - (d0.month < 7)
>
>That bools are confusable with 0 and 1 in Python is A Feature.
>

No partial-wink disclaimers?  Myself, I think casual maintainers
(and that *is* our target audience as Real-Life Programmers, 
right?) will find
  sy = d0.year
  if d0.month < 7:
      sy -= 1
best serves.
-- 

Cameron Laird <Cameron at Lairds.com>
Business:  http://www.Phaseit.net
Personal:  http://phaseit.net/claird/home.html




More information about the Python-list mailing list