"?:", "a and b or c" or "iif"

Hrvoje Niksic hniksic at srce.hr
Thu May 27 02:27:53 EDT 1999


"Tim Peters" <tim_one at email.msn.com> writes:

> No, -O doesn't do much:  binds the builtin name __debug__ to 0 and skips
> generating code for blocks of the form "if __debug__: xxx"; as a conceptual
> consequence of that, skips generating code for "assert" stmts;

?!?

I had no idea about asserts and -O!  Currently I'm using `assert' to
ensure logical correctness of some parts of the code before continuing
execution so that the system doesn't wind up in an in consistent
state, for instance:

    assert form.has_key('host')
    assert form.has_key('option')
    ... more asserts ...

    ... work with these things ...

> -OO goes on to throw away docstrings.

Yuck!

> If the revolting "(x and [a] ..." got popular, a peephole optimizer could
> get rid of the list ops -- but only at the cost of frustrating Michael and
> Neel's attempts to change what the generated code maps "0" to <0.9
> wink>.

I don't understand this.

> (x and (a,) or (b,))[0]-is-faster-ly y'rs  - tim

I'm curious -- why?  Is creating and referencing a tuple really faster 
than creating and referencing a list?




More information about the Python-list mailing list