(test) ? a:b

Chris Angelico rosuav at gmail.com
Sun Oct 26 02:20:04 CET 2014

On Sun, Oct 26, 2014 at 12:04 PM, Michael Torrie <torriem at gmail.com> wrote:
> But you can run
> into trouble if you tried to use a common python idiom like this:
> x = read_some_lines() 'returns number of lines read, or zero if none are
> if not x:
>         print ("I couldn't read any lines")
>         exit(1)
> Basically any value other than -1 for x would cause the not x to be
> true.

So don't use Python idioms in BASIC. :) Back when I used to write
BASIC code, I'd do explicit comparisons with zero for this sort of
thing... these days, I'd use Python idioms, but I'd also write Python
code :)

I think it's indicative that the BASIC code I'm most proud of was
consciously getting around language limitations (I wrote a mess of
code in assembly language and Q-BASIC to allow my programs to use the
mouse), but the Python code I'm most proud of is using the language's


More information about the Python-list mailing list