On 27/06/2019 18:58, James Lu wrote:
On Jun 26, 2019, at 7:13 PM, Chris Angelico
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 :-/ -- Rhodri James *-* Kynesim Ltd