dbfpy - cannot store new record

MRAB google at mrabarnett.plus.com
Thu May 21 11:00:34 EDT 2009


Laszlo Nagy wrote:
[snip]
> 
> I have never seen such a construct before. Index a tuple with a boolean???
> 
>                self.stream = file(f, ("r+b", "rb")[bool(readOnly)])
> 
Python originally didn't have Boolean; it used 0 for false and 1 for
true. When the Boolean class was added it was subclassed from int in
order not to break existing code, so False and True can be used like 0
and 1 respectively:

 >>> False == 0
True
 >>> True == 1
True
 >>> False + 1
1
 >>> True + 1
2

Therefore a_list[False] is the same as a_list[0] and a_list[True] is the
same as a_list[1].



More information about the Python-list mailing list