Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #94554
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'revision': 0.05; 'chunk': 0.07; 'exception.': 0.07; 'smallest': 0.07; 'thats': 0.07; 'valueerror:': 0.07; 'creighton': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:t 60': 0.09; 'ignore': 0.14; 'things.': 0.15; 'happily': 0.16; 'intuition': 0.16; 'pointers,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:array': 0.16; 'subject:program': 0.16; 'try/except': 0.16; 'wrote:': 0.16; 'laura': 0.18; 'stick': 0.18; 'try:': 0.18; 'input': 0.18; '2015': 0.20; 'posted': 0.21; 'work,': 0.21; 'pass': 0.22; 'errors': 0.23; 'forgot': 0.23; 'sat,': 0.23; 'this:': 0.23; 'written': 0.24; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'skip:m 30': 0.27; 'error': 0.27; '+0200,': 0.27; 'received:24': 0.28; 'code': 0.30; 'checks': 0.30; 'mention': 0.30; 'supposed': 0.31; 'especially': 0.32; 'run': 0.33; 'avoiding': 0.33; 'message- id:@gmail.com': 0.34; 'except': 0.34; 'running': 0.34; 'skip:c 30': 0.35; 'important.': 0.35; 'quite': 0.35; 'something': 0.35; 'sometimes': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'anything': 0.38; 'whatever': 0.39; 'along': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'telling': 0.61; 'real': 0.62; 'here.': 0.62; 'for:': 0.64; 'skip:a 40': 0.64; 'practice.': 0.66; 'skip:w 40': 0.66; 'jul': 0.72; 'received:shawcable.net': 0.84; 'received:wp.shawcable.net': 0.84; 'sort.': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Sebastian P. Luque <spluque@gmail.com> |
| Subject | Re: scalar vs array and program control |
| Date | Sat, 25 Jul 2015 10:30:58 -0500 |
| Organization | Church of Emacs |
| References | <87vbd850qa.fsf@gmail.com> <201507251101.t6PB1LqE021165@fido.openend.se> <201507251244.t6PCihmd023479@fido.openend.se> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| X-Gmane-NNTP-Posting-Host | s0106503955564c1f.wp.shawcable.net |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
| Cancel-Lock | sha1:rrrfTyvbWFami9NNh84TcvyHafA= |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.981.1437838289.3674.python-list@python.org> (permalink) |
| Lines | 49 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1437838289 news.xs4all.nl 2957 [2001:888:2000:d::a6]:40666 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:94554 |
Show key headers only | View raw
On Sat, 25 Jul 2015 14:44:43 +0200, Laura Creighton <lac@openend.se> wrote: > 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 Thanks so much for all the pointers, and especially how `try` is used in practice. Avoiding the tangle of checks for kind of input is precisely what my intuition was telling me. -- Seb
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: scalar vs array and program control Sebastian P. Luque <spluque@gmail.com> - 2015-07-25 10:30 -0500
csiph-web