using split for a string : error
Tobias M.
tm at tobix.eu
Thu Jan 24 06:16:50 EST 2013
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.
More information about the Python-list
mailing list