Re: using split for a string : error

Discussion in 'Python' started by Tobias M., Jan 24, 2013.

  1. Tobias M.

    Tobias M. Guest

    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.
    Tobias M., Jan 24, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    451
  2. Carlos Ribeiro
    Replies:
    11
    Views:
    684
    Alex Martelli
    Sep 17, 2004
  3. trans.  (T. Onoma)

    split on '' (and another for split -1)

    trans. (T. Onoma), Dec 27, 2004, in forum: Ruby
    Replies:
    10
    Views:
    201
    Florian Gross
    Dec 28, 2004
  4. Sam Kong
    Replies:
    5
    Views:
    226
    Rick DeNatale
    Aug 12, 2006
  5. Stanley Xu
    Replies:
    2
    Views:
    582
    Stanley Xu
    Mar 23, 2011
Loading...

Share This Page