[issue8134] collections.defaultdict gives KeyError with format()

Greg Jednaszewski report at bugs.python.org
Sat Mar 13 23:11:09 CET 2010


New submission from Greg Jednaszewski <jednaszewski at gmail.com>:

Found on 2.6.2 and 2.6.4:

I expect that printing an uninitialized variable from a defaultdict should work.  In fact it does with old-style string formatting.  However, when you try to do it with new-style string formatting, it raises a KeyError.

>>> import collections
>>> d = collections.defaultdict(int)
>>> "{foo}".format(d)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'foo'
>>> "%(foo)d" % d
'0'

----------
components: Library (Lib)
messages: 101025
nosy: jednaszewski
severity: normal
status: open
title: collections.defaultdict gives KeyError with format()
type: behavior
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8134>
_______________________________________


More information about the Python-bugs-list mailing list