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].
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to