On 6/27/19 1:58 PM, 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
James, have you considered investigating whether such things already
exist? I googled "python scanf", which took me to a Stack Overflow page,
which linked me to https://pypi.org/project/parse/, which could be just
what you are looking for.
--Ned.
_______________________________________________
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/AFTWKVQXPLQ672ASBFPPZS3BFZLVP54F/
Code of Conduct: http://python.org/psf/codeofconduct/