PEP 308: some candidate uses cases from live code
Tim Peters
tim_one at email.msn.com
Sun Feb 9 03:53:41 EST 2003
[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.
More information about the Python-list
mailing list