why won't slicing lists raise IndexError?

Rick Johnson rantingrickjohnson at gmail.com
Mon Dec 4 21:31:34 EST 2017


On Monday, December 4, 2017 at 7:47:20 PM UTC-6, Ned Batchelder wrote:

[...]
    
> Here are details filled in:
> 
>     $ python3.6
>     Python 3.6.3 (default, Oct  4 2017, 06:03:25)
>     [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin
>     Type "help", "copyright", "credits" or "license" for more information.
>      >>> def do_the_thing(seq, n):
>     ...     item = seq[n:n+1]
>     ...     if item:
>     ...         print(f"process({item})")
>     ...     else:
>     ...         print("do_without_item()")
>     ...
>      >>> do_the_thing([1, 2, 3], 2)
>     process([3])
>      >>> do_the_thing([1, 2, 3], 5)
>     do_without_item()
>      >>>

Thanks for filling in the blanks. However, my objection to
this else-clause stems from a perspective based in
pragmatics. Specifically, i see no benefit here in logging
the "non-action". Sure, perhaps logging a non-action may serve a
useful purpose during debugging sessions, but i find them to
be nothing but useless noise in production code.

Do you agree or disagree with my assessment?

If you disagree, please explain why.



More information about the Python-list mailing list