Is pythonic version of scanf() or sscanf() planned?

Terry Reedy tjreedy at udel.edu
Thu Oct 8 22:04:05 CEST 2009


ryniek90 wrote:
> On 6 Paź, 06:37, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
>> On Sun, 4 Oct 2009 15:48:16 -0700 (PDT), TerryP <bigboss1... at gmail.com>
>> declaimed the following in gmane.comp.python.general:
>>
>>> In the last 4 years, I have never missed functions like .*scanf() or
>>> atoi().
>>> It's probably a greeaaat thing that Python provides nether as built
>>> ins (per se).
>>         Uhm... Isn't the second one spelled "int()" <G>
>> --
>>         Wulfraed         Dennis Lee Bieber               KD6MOG
>>         wlfr... at ix.netcom.com      HTTP://wlfraed.home.netcom.com/
> 
> 
> 
> Ok thanks all for answers. Not counting .split() methods and regexps,
> there's nothing interesting.
> But I remember that lambda function also was unwelcome in Python, but
> finally it is and is doing well. So maybe someone, someday decide to
> put in Python an alternative, really great implementation of scanf() ?

scanf does three things: parses string fields out of text, optionally 
converts strings to numbers, and puts the results into pointed-to boxes. 
Since Python does not have pointer types, a python function cannot very 
well do the last, but has to return the tuple of objects. However, if a 
format string has named rather than positional fields, a Python function 
could either return a dict or set sttributes on an object. That could be 
useful.

If I were doing this, I would look into using the new str.format() 
strings rather than %-formatted strings.





More information about the Python-list mailing list