On Thu, Sep 17, 2020 at 09:44:09PM +0200, Alex Hall wrote:
> > 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.
"Often"? I'm curious about why you would want to do this, under what
circumstances, because I've never want to do this, let alone often, and
I can't think of why I might.
In any case, I think you are missing a very important point here. This
sort of scanf pattern matching is not just variable assignment targets,
but it includes a *pattern* to be matched, and we might need to build up
that pattern dynamically. A trivial example:
if day_of_week == 'Monday':
f'if today is Monday, this must be {country}' = string
elif day_of_week == 'Tuesday':
f'today is Tuesday, so we must be in {country}' = string
elif day_of_week == 'Wednesday':
f'if we're in {country} today must be Wednesday' = string
etc. Wouldn't it be much nicer to build up the pattern ahead of time?
I'd say it is essential to have the option, e.g. for translating
strings:
target = TARGETS[language]
f-target = string
but of course that doesn't work. But it could work if the pattern was a
regular string, and we applied a scanf function:
country = scanf(pattern, string)
sort of thing.
--
Steve
_______________________________________________
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/LNLCYRPJUZYSTZRHPWSS4CJQ3YR5HNGQ/
Code of Conduct: http://python.org/psf/codeofconduct/