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


Groups > comp.lang.python > #37577

Re: using split for a string : error

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
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; 'exception': 0.03; 'messages.': 0.04; 'case.': 0.05; 'python': 0.09; '(it': 0.09; 'abort': 0.09; 'imply': 0.09; 'literal': 0.09; 'subject:string': 0.09; 'subject:using': 0.09; 'valueerror': 0.09; 'programmer': 0.11; 'subject:error': 0.11; 'ignore': 0.13; '24,': 0.16; 'correctness.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'integers,': 0.16; 'landing': 0.16; 'supress': 0.16; 'sure.': 0.16; 'wrote:': 0.17; 'script.': 0.17; 'skip': 0.17; 'thu,': 0.17; 'jan': 0.18; 'trying': 0.21; "i'd": 0.22; "python's": 0.23; 'raise': 0.24; 'specifically': 0.24; 'header:In- Reply-To:1': 0.25; '(which': 0.26; 'checking': 0.27; 'first,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'chris': 0.28; "i'm": 0.29; 'maybe': 0.29; 'subject: : ': 0.30; 'error': 0.30; 'print': 0.32; 'to:addr:python-list': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'ahead': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; "didn't": 0.36; 'should': 0.36; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'help': 0.40; 'think': 0.40; 'worth': 0.63; 'more': 0.63; 'cast': 0.65; 'friendly': 0.71; '2013': 0.84; 'say:': 0.84; 'warning.': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=zycHD46icSndgOay15Sk841v0h4jemC0LvplomhNRuo=; b=QaM0aHNhIF98OTrCBkb1LOAKJzEw3FIp88w3njb9lwkfKEW6gdxJ6GcosUiMYci3W0 IV8PRlX2o6vaxDU5mkmSVUrgXDJQjhCPjQhv2EV1G4PXMfLkapGGy2aQrb/7XfOdZvOd BFvnRUqO8mii8LtkZ9fHgp0TJ7FMKdRbt1rBeHO1cJEsDKq7fUa8azEfQlYCprbQCQbo AFcOcDusqPpbv8PXRLIaJAcXx5e3J9Kk5Ecnd6a3Oa4e6axF0R93DL3uSTevQrFb4Bq3 ijOh1y5fh9rlKPSq4CE/g8b7xLfWDIv22rPYZ2OnFlOMAMkA9Ds1VSR+FVaIflWFKL9E Q8pA==
MIME-Version 1.0
X-Received by 10.68.230.135 with SMTP id sy7mr4175596pbc.76.1359028922641; Thu, 24 Jan 2013 04:02:02 -0800 (PST)
In-Reply-To <510121F9.70508@tobix.eu>
References <CAFqGZRGMXcku_nM_LqPsHpCzqGxF57LOSKwKwoCH+LyhPA8t_A@mail.gmail.com> <CAPTjJmpYi23Lx_4zuX28XURnAeaR-R=0w3e1mn6b0GBMs-O6Aw@mail.gmail.com> <51011822.3020702@tobix.eu> <CAPTjJmrqD7-x_sG_g-9YFFDanOct6_Grdw374EB69Kxy57LwLQ@mail.gmail.com> <510121F9.70508@tobix.eu>
Date Thu, 24 Jan 2013 23:02:02 +1100
Subject Re: using split for a string : error
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.974.1359028930.2939.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1359028930 news.xs4all.nl 6842 [2001:888:2000:d::a6]:36486
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:37577

Show key headers only | View raw


On Thu, Jan 24, 2013 at 10:58 PM, Tobias M. <tm@tobix.eu> wrote:
> Chris Angelico wrote:
>>
>> I'd not consider the performance, but the correctness. If you're
>> expecting them to be integers, just cast them, and specifically
>> _don't_ catch ValueError. Any non-integer value will then noisily
>> abort the script. (It may be worth checking for blank first, though,
>> depending on the data origin.)
>
> Well, when I said you should catch the ValueError I didn't imply you should
> ignore the error and supress any error messages. Of course this depents on
> the use case. Maybe you want to raise another exception with a more user
> friendly error message or you might want to skip the line and just print a
> warning. :)
>
> What I'm trying to say: When I give a script/program to a user who is not a
> python programmer I don't want him to see an error message like "ValueError:
> invalid literal for int() with base 10: 'abc'" as this would help him in no
> way.

Sure. Definitely. But for a proglet where the programmer IS the user
(which I think is one of Python's best use-cases), that exception
landing on the console is better than having to think ahead of time
about what might go wrong.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: using split for a string : error Chris Angelico <rosuav@gmail.com> - 2013-01-24 23:02 +1100

csiph-web