I have got KeyError while using collections.defaultdict with .format() method
Shell execution
In [1]: from collections import defaultdict
In [2]: foo = "Foo: {foo}\nBar: {bar}"
In [3]: default = defaultdict(lambda: 0)
In [4]: foo.format(**default)
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-4-799cab129cf2> in <module>
----> 1 foo.format(**default)
KeyError: 'foo'
I am not expecting a KeyError since I am using a defaultdict. Why this happening?
Apart from that, I would like to fill the foo variable with some default values, how can I do that?