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


Groups > comp.lang.python > #37563

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!newsfeed.freenet.ag!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; 'parsing': 0.07; 'raised': 0.07; 'strings.': 0.07; 'python': 0.09; 'currently,': 0.09; 'integers': 0.09; 'subject:string': 0.09; 'subject:using': 0.09; 'valueerror': 0.09; 'subject:error': 0.11; 'files.': 0.13; 'integers,': 0.16; 'received:188.40.28': 0.16; 'received:your- server.de': 0.16; 'wrote:': 0.17; 'file.': 0.20; 'supposed': 0.21; 'this:': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'values': 0.26; 'guess': 0.27; 'wonder': 0.27; 'replace': 0.27; 'chris': 0.28; 'convert': 0.29; 'subject: : ': 0.30; 'to:addr:python-list': 0.33; 'compared': 0.35; 'something': 0.35; 'there': 0.35; 'method': 0.36; 'should': 0.36; 'too': 0.36; 'subject:: ': 0.38; 'performance': 0.39; 'to:addr:python.org': 0.39; 'cast': 0.65; 'differences': 0.65
Date Thu, 24 Jan 2013 12:16:50 +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>
In-Reply-To <CAPTjJmpYi23Lx_4zuX28XURnAeaR-R=0w3e1mn6b0GBMs-O6Aw@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.962.1359026211.2939.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1359026211 news.xs4all.nl 6953 [2001:888:2000:d::a6]:49126
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:37563

Show key headers only | View raw


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.

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:16 +0100

csiph-web