![](https://secure.gravatar.com/avatar/d67ab5d94c2fed8ab6b727b62dc1b213.jpg?s=120&d=mm&r=g)
On Fri, Oct 23, 2020 at 12:31 AM Eric V. Smith <eric@trueblade.com> wrote:
On 10/22/2020 8:29 AM, Chris Angelico 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
On Thu, Oct 22, 2020 at 8:22 PM Steven D'Aprano <steve@pearwood.info> wrote: 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