scalar vs array and program control
lac at openend.se
Sat Jul 25 14:44:43 CEST 2015
And because I was rushed and posted without revision I left out something
>So this is, quite likely, the pattern that you are looking for:
>This is the usual way to do things.
I forgot to tell you that you are supposed to stick the try/except
around the smallest chunk of code that you expect to get the exception.
So you write this as
except ValueError: # whatever kind of error the real error is
The reason is that if you get any Value Errors in the part of the
code you always expect to work, then you don't want your program
to run happily along running the code for 'its a scalar'. You don't
want to hide real errors here.
The other thing I forgot to mention is that sometimes you don't want to
do anything but ignore any errors of this sort.
Thats written like this:
pass # just ignore it
More information about the Python-list