Message115924
Python 3.2a2+ (py3k:84613, Sep 7 2010, 19:17:31)
[GCC 4.4.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> "%s %(abc)s" % dict(abc=2)
"{'abc': 2} 2"
I did not expect this result. Looks like a bug to me.
>>> "%s %(abc)s" % (dict(abc=2), 4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: format requires a mapping
>>> "%d %(abc)s" % dict(abc=2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: %d format: a number is required, not dict
>>> "%s %s %(abc)s" % dict(abc=2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not enough arguments for format string
So, the only case which "works" (but is arguably buggy) is a single %s mixed in with dict lookups. 'may' does not adequately describe this reality. 'must' is much closer. If it weren't a backward incompatible change I'd suggest making a single dict (i.e.: non-tuple) argument to % with non-dict-lookup patterns an error. As it is, we'll just live with the quirk, and probably with the bug as well.
I'm not sure it is worth explaining all these quirks in the main docs. Perhaps in a footnote? |
|
Date |
User |
Action |
Args |
2010-09-09 02:15:41 | r.david.murray | set | recipients:
+ r.david.murray, eric.smith, docs@python, Ken.Basye |
2010-09-09 02:15:38 | r.david.murray | set | messageid: <1283998538.57.0.159508718882.issue9805@psf.upfronthosting.co.za> |
2010-09-09 02:15:36 | r.david.murray | link | issue9805 messages |
2010-09-09 02:15:36 | r.david.murray | create | |
|