Fix the NamespaceFormatter example in PEP 3101.
This commit is contained in:
parent
7751bd2554
commit
c0c1b9c215
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue