That surprises me. I put a quick test to check :On Fri, Sep 18, 2020 at 2:13 AM Alexis Masson <a.masson555@ntymail.com> wrote:This, in addition with locals().update(_), feels much better to me. Furthermore, it would allow other string-like classes, such as bytes or bytearray, to use that feature.But locals().update() isn't a supported operation, except in the situation where locals() is globals(). So what you're suggesting would work fine in the REPL but not in any production usage. ChrisA
def f() :prints :
print(locals())
locals().update(dict(a=3))
print(locals())
f()
================= RESTART: ****/test.py ================So maybe the specs don't force it, but under the current implementation, it seems to work.
{}
{'a': 3}
>>>
I agree that it's bad practice anyway; a correct solution to the original question might surely involve something akin to :for key, value in parsed.items() :
for key, value in parsed.items() :
exec(f"{key} = {value}")
I like the idea of needing to format a string in the process of parsing another ;)
Anyway, back on topic !