A difficulty I have with the idea as presented is this.
...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"
.
We can already do the reverse of this operation, of course:
>>> q = "{x:d} {y:d} {z:d}"
>>> d = dict(x=1, y=2, z=3)
>>> q = "{x:d} {y:d} {z:d}"
>>> q.format(**d)
'1 2 3'
What would be the operation we are inverting, here?
Perhaps a better way would be-- rather than assigning the values to the global x,y,z-- create a string method that returns a dictionary with the names and the values inside:
>>> q = "{x:d} {y:d} {z:d}"
>>> p = "1 2 3"
>>> q.parse(p)
{'x': 1, 'y': 2, 'z': 3}
..but of course this way we can to the same thing with the literal f-string, similar to what others have proposed:
>>> "{x:d} {y:d} {z:d}".parse("1 2 3")
{'x': 1, 'y': 2, 'z': 3}
---
Ricky.
"I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler