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