suppressing import errors

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Nov 15 17:34:34 EST 2011


On Tue, 15 Nov 2011 14:22:21 -0800, Chris Kaynor wrote:

> The tests (the code is shown later - its about 53 lines, with lots of
> copy+paste...):

Holy unnecessarily complicated code Batman!

This is much simpler:

[steve at ando ~]$ python -m timeit -s "x = None" "if x is None: pass"
10000000 loops, best of 3: 0.0738 usec per loop
[steve at ando ~]$ python -m timeit -s "x = True" "if x is None: pass"
10000000 loops, best of 3: 0.0799 usec per loop

The difference is too small to be significant. If I run the same tests 
multiple times, the winner could easily change.


-- 
Steven



More information about the Python-list mailing list