Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #94546 > unrolled thread

Re: scalar vs array and program control

Started byLaura Creighton <lac@openend.se>
First post2015-07-25 14:44 +0200
Last post2015-07-25 14:44 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: scalar vs array and program control Laura Creighton <lac@openend.se> - 2015-07-25 14:44 +0200

#94546 — Re: scalar vs array and program control

FromLaura Creighton <lac@openend.se>
Date2015-07-25 14:44 +0200
SubjectRe: scalar vs array and program control
Message-ID<mailman.976.1437828297.3674.python-list@python.org>
And because I was rushed and posted without revision I left out something
important.

>So this is, quite likely, the pattern that you are looking for:
>
>try:
>	all_your_code_which_is_happy_with_non_scalars
>except WhateverErrorPythonGivesYouWhenYouTryThisWithScalars:
>       whatever_you_want_to_do_when_this_happens
>
>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

code_you_expect_always_to_work
more_code_you_expect_always_to_work

try:
	these_four_lines_of_code_that_will_be_unhappy_if_its_a_scalar
except ValueError:	# whatever kind of error the real error is
       whatever_you_want_to_do_when_that_happens

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:

code_you_expect_always_to_work
more_code_you_expect_always_to_work

try:
	these_four_lines_of_code_that_will_be_unhappy_if_its_a_scalar
except ValueError:
       pass	    # just ignore it

Laura

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web