On 20/09/20 7:45 am, Christopher Barker wrote:
> In [4]: from parse import parse
> In [5]: parse("{x}{y}{z}", a_string)
> Out[5]: <Result () {'x': '2', 'y': '3', 'z': '4567'}>
>
> In [6]: parse("{x:d}{y:d}{z:d}", a_string)
> Out[6]: <Result () {'x': 2345, 'y': 6, 'z': 7}>
>
> So that's interesting -- different level of "greadiness" for strings
> than integers
Hmmm, that seems really unintuitive. I think a better result would
be a parse error -- "I was told to expect three things, but I only
found one."
That's what I mean when I say that the format language isn't well suited to parsing.
But it did find three things, or four, or .... that format specifier doesn't have any whitespace in between the {}s. So it isn't
looking for spaces between the numbers.
> I'm wondering whether such patterns should be disallowed on the
basis that they're inherently ambiguous.
I don't know that they are ambiguous, as long as the rules are laid out somewhere. Though confusing might be a good word :-)
-CHB