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


Groups > comp.lang.python > #37575

Re: using split for a string : error

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.134.4.91.MISMATCH!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <tm@tobix.eu>
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; 'correctness.': 0.16; 'integers,': 0.16; 'received:188.40.28': 0.16; 'received:your- server.de': 0.16; 'supress': 0.16; 'wrote:': 0.17; 'script.': 0.17; 'skip': 0.17; 'trying': 0.21; "i'd": 0.22; 'raise': 0.24; 'specifically': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'checking': 0.27; 'first,': 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; 'but': 0.36; "didn't": 0.36; 'should': 0.36; 'data': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'help': 0.40; 'worth': 0.63; 'more': 0.63; 'cast': 0.65; 'friendly': 0.71; 'say:': 0.84; 'warning.': 0.84
Date Thu, 24 Jan 2013 12:58:49 +0100
From "Tobias M." <tm@tobix.eu>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2
MIME-Version 1.0
To python-list@python.org
Subject Re: using split for a string : error
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>
In-Reply-To <CAPTjJmrqD7-x_sG_g-9YFFDanOct6_Grdw374EB69Kxy57LwLQ@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Authenticated-Sender tm@tobix.eu
X-Virus-Scanned Clear (ClamAV 0.97.5/16562/Thu Jan 24 00:40:16 2013)
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.972.1359028732.2939.python-list@python.org> (permalink)
Lines 16
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1359028732 news.xs4all.nl 6870 [2001:888:2000:d::a6]:32859
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:37575

Show key headers only | View raw


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.

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


Thread

Re: using split for a string : error "Tobias M." <tm@tobix.eu> - 2013-01-24 12:58 +0100

csiph-web