Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37645
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.022 |
| X-Spam-Evidence | '*H*': 0.96; '*S*': 0.00; 'suppress': 0.07; 'python': 0.09; 'subject:string': 0.09; 'subject:using': 0.09; 'subject:error': 0.11; 'benjamin': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'simplifies': 0.16; 'wrote:': 0.17; 'instance,': 0.17; 'string,': 0.17; 'jan': 0.18; 'sort': 0.21; "python's": 0.23; "i've": 0.23; 'header:In-Reply-To:1': 0.25; 'order.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'correct': 0.28; 'received:209.85.212': 0.28; 'chris': 0.28; 'fine': 0.28; 'behaviour': 0.29; 'complain': 0.29; 'yesterday.': 0.29; "i'm": 0.29; 'that.': 0.30; 'usually': 0.30; 'fri,': 0.30; 'subject: : ': 0.30; 'function': 0.30; 'error': 0.30; 'getting': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'operations': 0.33; 'received:google.com': 0.34; 'doing': 0.35; 'pm,': 0.35; 'sometimes': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'should': 0.36; 'received:209': 0.37; 'well.': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'most': 0.61; 'time,': 0.62; 'introduction': 0.62; 'fact,': 0.69; 'unusual': 0.71; '2013': 0.84; 'difference.': 0.84; 'front.': 0.84; 'oscar': 0.84 |
| 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:to:content-type; bh=V5dc7IOVUQQ8EmhoeTy1qeTj/3COSWl7kylT5lW6XAY=; b=IpKYgg8U1sRXAUX2K84nuyeKrXHrXgzHPrqT4QnzxObOvd1IcT2QReEQ31PGNJjhsW cEz/EAa5DUfMZMbh6aW5nmCsAy1O2SuYmNsEc0CwU14UHlS2W4mguTEC4VQzqCibb5F6 JJzQAAKrGPtLOf5Wpj4+0cc2Ii3qs3S5v6C3vcbHnKauzz6Wx4cFsh0IvKfGylF+JAJr pmdb7tZ23oCdb2azzZJkm5IZ6+Y7uVC7BYmFNzPL8i7l6HnOxFHJqvpdg8GOB/x26XgN jF3Z8VF3f2nEGPUjqMxov2UFK1It4vbAHZgehgh15UTgQiqOTpz19Zr6OBE6H3d2iJSP 4jzA== |
| MIME-Version | 1.0 |
| X-Received | by 10.52.20.50 with SMTP id k18mr3705586vde.91.1359076301552; Thu, 24 Jan 2013 17:11:41 -0800 (PST) |
| In-Reply-To | <CAHVvXxRCE02b=R5NgTNy0qcmts7YFCpVtXWM3cLizkRXwRDNog@mail.gmail.com> |
| References | <CAFqGZRGMXcku_nM_LqPsHpCzqGxF57LOSKwKwoCH+LyhPA8t_A@mail.gmail.com> <CAPTjJmpYi23Lx_4zuX28XURnAeaR-R=0w3e1mn6b0GBMs-O6Aw@mail.gmail.com> <51011822.3020702@tobix.eu> <CAPTjJmrqD7-x_sG_g-9YFFDanOct6_Grdw374EB69Kxy57LwLQ@mail.gmail.com> <CAHVvXxRCE02b=R5NgTNy0qcmts7YFCpVtXWM3cLizkRXwRDNog@mail.gmail.com> |
| Date | Fri, 25 Jan 2013 12:11:41 +1100 |
| Subject | Re: using split for a string : error |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| 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.1026.1359076304.2939.python-list@python.org> (permalink) |
| Lines | 56 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1359076304 news.xs4all.nl 6982 [2001:888:2000:d::a6]:48259 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:37645 |
Show key headers only | View raw
On Fri, Jan 25, 2013 at 12:03 PM, 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") == 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().
It simplifies operations on strings that contain numbers. For
instance, here's a problem from yesterday. I have a set of files (MIDI
files of The Rose of Persia) which have been sloppily numbered:
Rose_1.mid
Rose_10.mid
Rose_11.mid
Rose_12.mid
Rose_13.mid
Rose_14.mid
Rose_15.mid
Rose_16.mid
Rose_17.mid
Rose_18.mid
Rose_19.mid
Rose_2.mid
Rose_20.mid
Rose_21.mid
Rose_22.mid
Rose_23.mid
Rose_24.mid
Rose_3.mid
Rose_4.mid
Rose_5.mid
Rose_6.mid
Rose_7.mid
Rose_8.mid
Rose_9.mid
Rose_Int.mid
They're not in order. The one marked "Int" is the Introduction and
should be first; then Rose_1 ... Rose_9, then Rose_10 ... Rose_24. In
fact, the correct sort order is exactly:
atoi(filename[5:])
Most of the time, it makes no difference. Python's int() will do
exactly what atoi() does. It's only in the unusual case where they
even differ.
ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: using split for a string : error Chris Angelico <rosuav@gmail.com> - 2013-01-25 12:11 +1100
csiph-web