Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.straub-nv.de!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'caller': 0.07; 'suppress': 0.07; 'python': 0.09; '(0,': 0.09; '0),': 0.09; 'raised.': 0.09; 'received:mail-vb0-f46.google.com': 0.09; 'subject:string': 0.09; 'subject:using': 0.09; 'tuple': 0.09; 'valueerror': 0.09; 'cc:addr :python-list': 0.10; 'def': 0.10; 'subject:error': 0.11; 'cases': 0.15; '>>': 0.16; 'benjamin': 0.16; 'csv': 0.16; 'inconvenient': 0.16; 'wrote:': 0.17; 'string,': 0.17; 'jan': 0.18; '>>>': 0.18; 'received:209.85.212.46': 0.18; 'email addr:gmail.com>': 0.20; 'meant': 0.21; '>>>': 0.22; 'int,': 0.22; 'defined': 0.22; 'cc:2**0': 0.23; 'example': 0.23; '>': 0.23; "i've": 0.23; 'cc:addr:python.org': 0.25; 'header :In-Reply-To:1': 0.25; 'leave': 0.26; 'am,': 0.27; 'right.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'chris': 0.28; 'decide': 0.28; 'fine': 0.28; '>>>>': 0.29; 'behaviour': 0.29; 'cases.': 0.29; 'complain': 0.29; 'remains': 0.29; 'served': 0.29; 'url:mailman': 0.29; 'skip:& 10': 0.29; "i'm": 0.29; 'that.': 0.30; 'usually': 0.30; 'fri,': 0.30; 'subject: : ': 0.30; 'function': 0.30; 'error': 0.30; 'url:python': 0.32; 'could': 0.32; 'url:listinfo': 0.32; 'getting': 0.33; 'int': 0.33; 'received:google.com': 0.34; 'said,': 0.35; 'doing': 0.35; 'sometimes': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'url:org': 0.36; 'characters': 0.36; 'url:library': 0.36; 'useful': 0.36; 'should': 0.36; 'option': 0.37; 'being': 0.37; 'received:209': 0.37; 'well.': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'gives': 0.39; 'where': 0.40; 'url:mail': 0.40; 'think': 0.40; 'most': 0.61; 'more': 0.63; 'as:': 0.75; '2013': 0.84; 'front.': 0.84; 'neil': 0.84; 'oscar': 0.84; 'joel': 0.91; 'to:none': 0.93; 'family.': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:cc:content-type; bh=vrOarT9W04TMi8S49VwIXDoNJg33J4yYeM4rkdwjMPI=; b=LCGpSy7HGQzP7wLwODjwkcB7VPDjZkoCjFoMSPN7pP6zs8s590zhSk60GKx7kzxMeJ j0eG48QUEQ/wQ/bEXWxqrsYx9expUIDpt/C3dJoSuWrvnZ2sIafJEVy79Z5HRg5nbMJa 4Jf8WFIoQcAiQXShUAaBVDT6tpXFHei24OrsvRt3DOxMGl66XD5bMJrtCVyYbBXAApls NPr25Z47dxH+dC8G+AQSD3sQWAYpPskiBaJbkF3JE3I42d/JIkniBiUjMYl33KGzAA8h vxZu1e6v/3z+e8E3kWcnjdZxvjWTBlj91H8Z9XNR82aHAgKXcGWZADSJbcP6PDvigqFp gH2g== MIME-Version: 1.0 X-Received: by 10.220.150.83 with SMTP id x19mr6149474vcv.25.1359125043962; Fri, 25 Jan 2013 06:44:03 -0800 (PST) In-Reply-To: <51029739$0$6876$e4fe514c@news2.news.xs4all.nl> References: <51011822.3020702@tobix.eu> <51029739$0$6876$e4fe514c@news2.news.xs4all.nl> Date: Fri, 25 Jan 2013 09:44:03 -0500 Subject: Re: using split for a string : error From: Joel Goldstick Cc: "python-list@python.org" Content-Type: multipart/alternative; boundary=f46d0434bf9c73618d04d41df54a X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 146 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359125053 news.xs4all.nl 6906 [2001:888:2000:d::a6]:34235 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37671 --f46d0434bf9c73618d04d41df54a Content-Type: text/plain; charset=UTF-8 Don't forget to look at csv reader. http://docs.python.org/2/library/csv.html On Fri, Jan 25, 2013 at 9:31 AM, Hans Mulder wrote: > On 25/01/13 15:04:02, Neil Cerutti wrote: > > On 2013-01-25, Oscar Benjamin wrote: > >> On 24 January 2013 11:35, Chris Angelico wrote: > >>> It's usually fine to have int() complain about any > >>> non-numerics in the string, but I must confess, I do sometimes > >>> yearn for atoi() semantics: atoi("123asd") == 123, and > >>> atoi("qqq") == 0. I've not seen a convenient Python function > >>> for doing that. Usually it involves manually getting the > >>> digits off the front. All I want is to suppress the error on > >>> finding a non-digit. Oh well. > >> > >> I'm interested to know what the situations are where you want > >> the behaviour of atoi(). > > > > Right. atoi is no good even in C. You get much better control > > using the sprintf family. > > I think you meant sscanf. > > It's true that sscanf gives you more control. That being said, > sometimes the one option atoi gives you, just happens to be what > you need. > > > int would need to return a tuple of the > > number it found plus the number of characters consumed to be more > > useful for parsing. > > > >>>> intparse("123abc") > > (123, 3) > > > > But that would make it might inconvenient for general use. > > If the new function is nameed intparse, and the existing int > function remains available, then most use cases would be served > by int, and intparse would be available as a building block for > other use cases. For example atoi could be defined as: > > def atoi(s): return intparse(s)[0] > > intparse("xyz") should return (0, 0), and leave it to the caller > to decide whether a ValueError shoud be raised. > > > -- HansM > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com --f46d0434bf9c73618d04d41df54a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Don't forget to look at csv reader.

http://docs.python.org/2/library= /csv.html


On Fri, Jan 25, 2013 at 9:31 AM, Hans Mulder <hansmu@xs4all.nl> wrote:
On 25/01/13 15:04:02, Neil Cerutti wrote:
> On 2013-01-25, Oscar Benjamin <oscar.j.benjamin@gmail.com> wrote:
>> On 24 January 2013 11:35, Chris Angelico <rosuav@gmail.com> wrote:
>>> It's usually fine to have int() complain about any
>>> non-numerics in the string, but I must confess, I do sometimes=
>>> yearn for atoi() semantics: atoi("123asd") =3D=3D 12= 3, and
>>> atoi("qqq") =3D=3D 0. I've not seen a convenient= Python function
>>> for doing that. Usually it involves manually getting the
>>> digits off the front. All I want is to suppress the error on >>> finding a non-digit. Oh well.
>>
>> I'm interested to know what the situations are where you want<= br> >> the behaviour of atoi().
>
> Right. atoi is no good even in C. You get much better control
> using the sprintf family.

I think you meant sscanf.

It's true that sscanf gives you more control. =C2=A0That being said, sometimes the one option atoi gives you, just happens to be what
you need.

> int would need to return a tuple of the
> number it found plus the number of characters consumed to be more
> useful for parsing.
>
>>>> intparse("123abc")
> (123, 3)
>
> But that would make it might inconvenient for general use.

If the new function is nameed intparse, and the existing int
function remains available, then most use cases would be served
by int, and intparse would be available as a building block for
other use cases. =C2=A0For example atoi could be defined as:

def atoi(s): return intparse(s)[0]

intparse("xyz") should return (0, 0), and leave it to the caller<= br> to decide whether a ValueError shoud be raised.


-- HansM




--
http://mail.python.org/mailman/listinfo/python-list



--
--f46d0434bf9c73618d04d41df54a--