Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: using split for a string : error

Thread Tools

Re: using split for a string : error

Tobias M.
Posts: n/a
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.
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: using split for a string : error Chris Angelico Python 0 01-24-2013 10:58 AM
Re: using split for a string : error Tobias M. Python 0 01-24-2013 10:55 AM
How to use String.split to split a mixed encoding string(partencoded in gbk, part encoded in utf-8) Stanley Xu Ruby 2 03-23-2011 02:06 PM
String#split(/\s+/) vs. String#split(/(\s+)/) Sam Kong Ruby 5 08-12-2006 07:59 PM
Small inconsistency between string.split and "".split Carlos Ribeiro Python 11 09-17-2004 05:57 PM