<div dir="ltr">Don't forget to look at csv reader.<br><br><a href="http://docs.python.org/2/library/csv.html">http://docs.python.org/2/library/csv.html</a><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Fri, Jan 25, 2013 at 9:31 AM, Hans Mulder <span dir="ltr"><<a href="mailto:hansmu@xs4all.nl" target="_blank">hansmu@xs4all.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 25/01/13 15:04:02, Neil Cerutti wrote:<br>
> On 2013-01-25, Oscar Benjamin <<a href="mailto:oscar.j.benjamin@gmail.com">oscar.j.benjamin@gmail.com</a>> wrote:<br>
>> On 24 January 2013 11:35, Chris Angelico <<a href="mailto:rosuav@gmail.com">rosuav@gmail.com</a>> wrote:<br>
>>> It's usually fine to have int() complain about any<br>
>>> non-numerics in the string, but I must confess, I do sometimes<br>
>>> yearn for atoi() semantics: atoi("123asd") == 123, and<br>
>>> atoi("qqq") == 0. I've not seen a convenient Python function<br>
>>> for doing that. Usually it involves manually getting the<br>
>>> digits off the front. All I want is to suppress the error on<br>
>>> finding a non-digit. Oh well.<br>
>><br>
>> I'm interested to know what the situations are where you want<br>
>> the behaviour of atoi().<br>
><br>
> Right. atoi is no good even in C. You get much better control<br>
> using the sprintf family.<br>
<br>
</div>I think you meant sscanf.<br>
<br>
It's true that sscanf gives you more control. That being said,<br>
sometimes the one option atoi gives you, just happens to be what<br>
you need.<br>
<div class="im"><br>
> int would need to return a tuple of the<br>
> number it found plus the number of characters consumed to be more<br>
> useful for parsing.<br>
><br>
>>>> intparse("123abc")<br>
> (123, 3)<br>
><br>
> But that would make it might inconvenient for general use.<br>
<br>
</div>If the new function is nameed intparse, and the existing int<br>
function remains available, then most use cases would be served<br>
by int, and intparse would be available as a building block for<br>
other use cases. For example atoi could be defined as:<br>
<br>
def atoi(s): return intparse(s)[0]<br>
<br>
intparse("xyz") should return (0, 0), and leave it to the caller<br>
to decide whether a ValueError shoud be raised.<br>
<br>
<br>
-- HansM<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr"><div>Joel Goldstick<br></div><a href="http://joelgoldstick.com" target="_blank">http://joelgoldstick.com</a><br></div>
</div>