PEP 285: Adding a bool type

James Logajan JamesL at Lugoj.com
Sat Apr 6 14:33:31 EST 2002


"John Roth" <johnroth at ameritech.net> wrote:
> The original example was something like
> 
> number of days in year = 365 + isLeap(year).
> 
> To put it bluntly, that's a very confusing hack that depends
> on conceptual True being 1 and conceptual False being
> zero.

Just FYI, that example is not quite theoretical since you can find almost 
equivalent usage in the standard Lib/calendar.py module:

# Return weekday (0-6 ~ Mon-Sun) and number of days (28-31) for year, month
def monthrange(year, month):
    if not 1 <= month <= 12: raise ValueError, 'bad month number'
    day1 = weekday(year, month, 1)
    ndays = mdays[month] + (month == February and isleap(year))
    return day1, ndays

Of course in this case it is the result of the "and" that is being treated 
as an integer.



More information about the Python-list mailing list