Fix the NamespaceFormatter example in PEP 3101.

This commit is contained in:
Georg Brandl 2010-04-02 08:54:11 +00:00
parent 7751bd2554
commit c0c1b9c215
1 changed files with 3 additions and 3 deletions

View File

@ -595,9 +595,9 @@ Customizing Formatters
if isinstance(key, str):
try:
# Check explicitly passed arguments first
return kwds[name]
return kwds[key]
except KeyError:
return self.namespace[name]
return self.namespace[key]
else:
Formatter.get_value(key, args, kwds)
@ -607,7 +607,7 @@ Customizing Formatters
fmt = NamespaceFormatter(globals())
greeting = "hello"
print(fmt("{greeting}, world!"))
print(fmt.format("{greeting}, world!"))
A similar technique can be done with the locals() dictionary to
gain access to the locals dictionary.