On Wed, Oct 21, 2020 at 7:12 PM David Mertz <[email protected]> wrote:

> To bring it back to a concrete idea, here's how I see things:
>
>    1. The idea of f-string-like assignment targets has little support.
>    Only Chris, and maybe the OP who seems to have gone away.
>    2. The idea of a "scanning language" seems to garner a fair amount of
>    enthusiasm from everyone who has commented.
>    3. Having the scanning language be "inspired by" f-strings seems to
>    fit nicely with Python
>    4. Lots of folks like C scanf() as another inspiration for the need.
>    I was not being sarcastic in saying that I thought COBOL PICTURE clauses
>    are another similar useful case.  I think Perl 6 "rules" were trying to do
>    something along those lines... but, well, Perl.
>    5. In my opinion, this is naturally a function, or several related
>    functions, not new syntax (I think Steven agrees)
>
> So the question is, what should the scanning language look like?  Another
> question is: "Does this already exist?"
>
> I'm looking around PyPI, and I see this that looks vaguely along the same
> lines. But most likely I am missing things:
> https://pypi.org/project/rebulk/
>
> In terms of API, assuming functions, I think there are two basic models.
> We could have two (or more) functions that were related though:
>
> # E.g. pat_with_names = "{foo:f}/{bar:4s}/{baz:3d}"
> matches = scan_to_obj(pat_with_names, haystack)
> # something like (different match objects are possible choices, dict,
> dataclass, etc)
> print(matches.foo)
> print(maches['bar'])
>
> Alternately:
>
> # pat_only = "{:f}/{:4s}/{:3d}"
> foo, bar, baz = scan_to_tuple(pat_only, haystack)
> # names, if bound, have the types indicated by scanning language
>
> There are questions open about partial matching, defaults, exceptions to
> raise, etc.  But the general utility of something along those lines seems
> roughly consensus.
>

Hmm, if the above is acceptable, maybe f-strings are still the logical next
step, since they bring the format and the target name together again.

-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/HMWA3BNDSBYAEPJ5RXBWB6Q2RGENLXDY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to