[issue8134] collections.defaultdict gives KeyError with format()
New submission from Greg Jednaszewski jednaszew...@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 rep...@bugs.python.org http://bugs.python.org/issue8134 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8134] collections.defaultdict gives KeyError with format()
Changes by Ezio Melotti ezio.melo...@gmail.com: -- nosy: +eric.smith, ezio.melotti priority: - normal stage: - test needed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8134 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8134] collections.defaultdict gives KeyError with format()
Eric Smith e...@trueblade.com added the comment: str.format() does not take a mapping object. You want: {0[foo]}.format(d) '0' -- resolution: - invalid stage: test needed - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8134 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8134] collections.defaultdict gives KeyError with format()
Greg Jednaszewski jednaszew...@gmail.com added the comment: Oops, thanks. I should have known that. However, should this work? This is what initially led me to file this ticket. My initial example was a bad one. from collections import defaultdict d = defaultdict(int) d['bar'] += 1 {bar}.format(**d) '1' {foo}.format(**d) Traceback (most recent call last): File stdin, line 1, in module KeyError: 'foo' -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8134 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8134] collections.defaultdict gives KeyError with format()
Benjamin Peterson benja...@python.org added the comment: No, because that's not the behavior of keyword arguments. -- nosy: +benjamin.peterson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8134 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8134] collections.defaultdict gives KeyError with format()
Eric Smith e...@trueblade.com added the comment: See also issue 6081. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8134 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com