why won't slicing lists raise IndexError?

Python python at bladeshadow.org
Thu Dec 7 21:02:31 EST 2017


Hi Rick!

On Wed, Dec 06, 2017 at 04:05:42PM -0800, Rick Johnson wrote:
> Python wrote:
> 
> [...]
> 
> > THIS IS FALSE.  CALLING A FUNCTION
> 
> What *FUNCTION*?

In this snippet (which again, we agreed was an incomplete academic
example):

    if item:
        process(item)
    else:
        do_without_item()

Can you please explain to me what sort of Python syntactical construct
do_without_item() could be, other than a call to a Python callable
object (i.e. a function)?  Then, could you explain to me how that
particular syntactical construct is in any way equivalent to the pass
statement?  Could you then explain to me how using that in the simple
example given makes any sense whatsoever?

[FWIW, if there is an answer to this, I am genuinely interested...]

Since it can indeed be a function call, then if you can't do all of
the above things, doesn't that imply that in the example given,
do_witout_item() can't be anything BUT a function call?  Even if it
somehow doesn't by some logic that escapes me, for the purposes of
this simple academic example, isn't it preferable to assume that it is
the most obvious thing (i.e. a function call)?

Isn't the else clause in fact NOT superfluous, because it illustrates
that if the slice operation would be out of the container object's
bounds, then item will be assigned a value that evaluates to false,
enabling one to trigger the else clause of an if block to do something
ONLY under that condition?

> if "do_without_item()" had been defined, then you could call
> it a function. But until you do, it's just a NameError.

OK!  Then could you explain to me how a NameError is equivalent to the
pass statement?  I thought one continued execution without any side
effects, and the other required handling or else will stop the
program.  Isn't that in fact functionally nonequivalent?

Thanks.




More information about the Python-list mailing list