On Fri, Oct 23, 2020 at 12:31 AM Eric V. Smith <e...@trueblade.com> wrote: > > On 10/22/2020 8:29 AM, Chris Angelico wrote: > > On Thu, Oct 22, 2020 at 8:22 PM Steven D'Aprano <st...@pearwood.info> wrote: > >> Another problem is that using only a literal/display form as a target > >> means you can't pre-assemble a pattern and apply it later: > >> > >> # Match only the given domain. > >> domain = get_wanted_domain() > >> pattern = 'email: {name}@%s' % domain > >> # ... now what? > > Right, and you can't do that with f-strings on the RHS either. The > > specific thing you're asking about could easily be implemented as a > > feature of the minilanguage itself, but I'm not sure it'd actually be > > needed. Building patterns for future parsing is simply not the job of > > this feature - use a regex if you need that. > > In the case of f-strings, the fallback is str.format(), which uses the > exact same format specifiers. What's the equivalent when you need > dynamic 'f-string assignment targets'? >
Good question, but whatever it is, it can be part of the same proposal. A standard library function that does the same kind of thing but returns a dictionary would be useful, even if it isn't as important. Pike has sscanf (compiler feature that assigns directly to things) and array_sscanf (returns a sequential collection of matched items), and Python could do the same kind of thing. Returning a dict would be FAR less convenient for the most common cases, but as you say, it'd be the fallback for when you need dynamic parsing. ChrisA _______________________________________________ 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/7IQKA7F2VCF6QLYXILZY4I5KLOTMFBSM/ Code of Conduct: http://python.org/psf/codeofconduct/