On Thu, Sep 17, 2020 at 9:27 PM Ricky Teachey <ri...@teachey.org> wrote:

>
> On Thu, Sep 17, 2020 at 2:57 PM Brendan Barnwell <brenb...@brenbarn.net>
> wrote:
>
>> On 2020-09-16 21:52, Dennis Sweeney wrote:
>> > TL;DR: I propose the following behavior:
>> >
>> >      >>> s = "She turned me into a newt."
>> >      >>> f"She turned me into a {animal}." = s
>> >      >>> animal
>> >      'newt'
>> >
>> >      >>> f"A {animal}?" = s
>> >      Traceback (most recent call last):
>> >      File "<pyshell#2>", line 1, in <module>
>> >              f"A {animal}?" = s
>> >      ValueError: f-string assignment target does not match 'She turned
>> me into a newt.'
>> >
>> >      >>> f"{hh:d}:{mm:d}:{ss:d}" = "11:59:59"
>> >      >>> hh, mm, ss
>> >      (11, 59, 59)
>>
>
> A difficulty I have with the idea as presented is this.
>
> If I can say this:
>
> "{x:d} {y:d} {z:d}" = "1 2 3"
>
> ...thus assigning 1, 2, 3 to x, y, z respectively, I might want to also do
> the same thing this way:
>
> q = "{x:d} {y:d} {z:d}"
> q = "1 2 3"
>
> The intent being: save the f-string as a variable, and then use it to
> assign later. But that can obviously never work because q would just become
> the string "1 2 3" .
>

The same problem exists for assignments to tuples, subscripts, attributes,
even plain variables. I've often wanted to put an assignment target in a
variable.
_______________________________________________
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/X6YFOHNNWGOKLLJMEG2K5EWRRTT7KZKI/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to