On 9/18/2020 8:19 AM, Ricky Teachey wrote:
On Fri, Sep 18, 2020, 8:17 AM Ricky Teachey <ricky@teachey.org> wrote:
Why not just grow a parse method on str that returns a dict and do it this way?
q = "{a} {b}"
p = "1 2"(a, b) = q.parse(p)
Sorry that should have been:
(a, b) = q.parse(p).values()
I don't understand why returning a dict is useful. Unless this becomes as complicated as regexes with grouping, etc. (in which case: use a regex), the values will be returned in the order they appear in the template string. So just have it return a tuple:
a, b = q.parse(p)
Or for something that could be written today:
a, b = parse("{:d} {:d}", "1 2")
assert a == 1 and b == 2I don't see the need for new syntax or new ways to assign values. You're not even removing any duplication compared to:
f"{a:d} {b:d}" = "1 2"