> On 28 Jun 2019, at 19:01, Rhodri James <rho...@kynesim.co.uk> wrote:
> 
> On 27/06/2019 18:58, James Lu wrote:
>>> On Jun 26, 2019, at 7:13 PM, Chris Angelico <ros...@gmail.com> wrote:
>>> 
>>> The main advantage of sscanf over a regular expression is that it
>>> performs a single left-to-right pass over the format string and the
>>> target string simultaneously, with no backtracking. (This is also its
>>> main DISadvantage compared to a regular expression.) A tiny amount of
>>> look-ahead in the format string is the sole exception (for instance,
>>> format string "%s$%d" would collect a string up until it finds a
>>> dollar sign, which would otherwise have to be written "%[^$]$%d").
>>> There is significant value in having an extremely simple parsing tool
>>> available; the question is, is it worth complicating matters with yet
>>> another way to parse strings? (We still have fewer ways to parse than
>>> ways to format strings. I think.)
>> I agree. Python should have an equivalent of scanf, but perhaps it should 
>> have some extensions:
>> %P - read pickled object
>> %J - read JSON object
>> %M - read msgpack object
> 
> I somewhat disagree; scanf (or rather sscanf) always looks like a brilliant 
> idea right up until I come to use it, at which point I almost always do 
> something else that gives me better control.  I get very paranoid about 
> parsing, and rolling my own usually feels safer.  Whether or not it is safer 
> is, of course, another issue :-/


And let's not forgot how bad positional matching is. So if one were to 
implement such a library it would be best if one can supply names for the the 
parts and have it spit out a dict. 

/ Anders 
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/TB3OV5VU7HQYGU7BTLHP7HWRGCRSL7CT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to