Message343363
Hi @vykouk, Python evaluates arguments before calling functions so
>>> dicti.get(key, dflt(key))
is equivalent to:
>>> arg = dflt(key)
>>> dicti.get(key, arg)
Notive how dflt() is called before .get()
This is how all functions work in Python, not just dict methods.
You can change your code like so to make it work:
>>> if key in dicti:
>>> x = dicti[key]
>>> else:
>>> x = dflt(key)
or use defaultdict instead of setdefault which will take a callable to generate the default value.
I don't think there is a bug and we can close this issue.
Have a nice day. |
|
Date |
User |
Action |
Args |
2019-05-24 09:45:20 | remi.lapeyre | set | recipients:
+ remi.lapeyre, vykouk |
2019-05-24 09:45:20 | remi.lapeyre | set | messageid: <1558691120.39.0.318095054621.issue37033@roundup.psfhosted.org> |
2019-05-24 09:45:20 | remi.lapeyre | link | issue37033 messages |
2019-05-24 09:45:20 | remi.lapeyre | create | |
|