[issue37318] builtins.True exists but can't be accessed
Raymond Hettinger
report at bugs.python.org
Mon Jun 17 18:07:56 EDT 2019
Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:
Depending on your mental model of the language, this may not seem odd at all.
>>> # We can set any key/value pair in any dictionary
>>> d = {'x': 10, 'True': 20, 'for': 30}
>>> # We can do regular string lookups at any time
>>> d['x']
10
>>> d['True']
20
>>> d['for']
30
>>> # globals() isn't special in this regard
>>> globals().update(d)
>>> globals()['x']
10
>>> globals()['True']
20
>>> globals()['for']
30
>>> # Globals is special though in that it provides
>>> # a fast way to do lookups for keys that are
>>> # valid identifiers and are not keywords
>>> x # Fast lookup equivalent to globals['x']
10
>>> True # This is a keyword, so there is no lookup
True
>>> for # This is a keyword, so there is no lookup
SyntaxError: invalid syntax
At any rate, this isn't a bug. It is just the way the language works.
Thank you for the report.
----------
nosy: +rhettinger
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37318>
_______________________________________
More information about the Python-bugs-list
mailing list