On Tue, Oct 20, 2020 at 10:37 PM Rob Cliffe via Python-ideas
<python-ideas@python.org> wrote:
> In short, "assigning" to f-strings is not and cannot be a simple reversal  of 
> having them in expressions.  Rather, it is opening a big can of worms.
>

It's not a reversal of them being in expressions any more than
assigning to a list display is a reversal of constructing a list. It's
a parallel operation, a counterpart.

It would be Python's way of offering an sscanf-like operation, which
is something that I've frequently wished for. Regular expressions
aren't ideal for all situations, and there are plenty of times when a
simple set of parsing rules could be very nicely encoded into a
compact form like this. C's sscanf and sprintf aren't perfect
counterparts, but they're incredibly valuable. Python has percent
formatting for sprintf, but no form of sscanf.

> There is no precedent in Python for an expression on the LHS of an 
> assignment.  (Tuple unpacking, dotted names, slices, dictionary keys etc. 
> might or might not be considered counter-examples but at least their intent 
> is clear.)  Certainly not for something which looks like a literal on the LHS 
> of an assignment.
>

And the intent here would be just as clear. Assigning to a tuple or
list has very well defined semantics, and they don't perfectly
correspond to the way you would construct such a thing on the RHS. So,
they *are* precedent for this.

An sscanf format string is simple, easily understood, and unambiguous.
An f-string assignment target would be the same, but using f-string
style notation instead. It's that simple.

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/2BFCFPDBV4OCTBOGV5UWKX6DJZKBEUUE/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to