Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37663
| From | Neil Cerutti <neilc@norwich.edu> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: using split for a string : error |
| Date | 2013-01-25 14:04 +0000 |
| Organization | Norwich University |
| Message-ID | <amfhmiFgto8U1@mid.individual.net> (permalink) |
| 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> <mailman.1024.1359075803.2939.python-list@python.org> |
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") == 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. 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.
--
Neil Cerutti
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: using split for a string : error Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-01-25 01:03 +0000
Re: using split for a string : error Neil Cerutti <neilc@norwich.edu> - 2013-01-25 14:04 +0000
Re: using split for a string : error Hans Mulder <hansmu@xs4all.nl> - 2013-01-25 15:31 +0100
Re: using split for a string : error Joel Goldstick <joel.goldstick@gmail.com> - 2013-01-25 09:44 -0500
Re: using split for a string : error Neil Cerutti <neilc@norwich.edu> - 2013-01-25 15:14 +0000
csiph-web