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:
    >
    >
    > The other thing you may want to consider, if the values are supposed
    > to be integers, is to convert them to Python integers before
    > comparing. Currently, you're working with strings. Replace this:
    >
    > if sp[9] == sp[10]:
    >
    > with this:
    >
    > if int(sp[9]) == int(sp[10]):

    I thought of this too and I wonder if there are any major differences
    regarding performance compared to using the strip() method when parsing
    large files.

    In addition I guess one should catch the ValueError that might be raised
    by the cast if there is something else than a number in the file.
    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:
    466
  2. Carlos Ribeiro
    Replies:
    11
    Views:
    696
    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:
    213
    Florian Gross
    Dec 28, 2004
  4. Sam Kong
    Replies:
    5
    Views:
    238
    Rick DeNatale
    Aug 12, 2006
  5. Stanley Xu
    Replies:
    2
    Views:
    604
    Stanley Xu
    Mar 23, 2011
Loading...

Share This Page