why won't slicing lists raise IndexError?
Chris Angelico
rosuav at gmail.com
Mon Dec 4 21:37:58 EST 2017
On Tue, Dec 5, 2017 at 1:31 PM, Rick Johnson
<rantingrickjohnson at gmail.com> wrote:
> 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.
Why do you believe this to be a non-action? There is no indication
that do_without_item does nothing.
ChrisA
More information about the Python-list
mailing list