Reading Built-in Constants one can see that for example False
is a built-in constant.
It is possible to retrieve it using:
>>> print(getattr(__builtins__, "False"))
False
But this fails:
>>> print(__builtins__.False)
File "<stdin>", line 1
print(__builtins__.False)
^^^^^
SyntaxError: invalid syntax
I assume this fails because the word “False” (without quotes) gets recognized by the interpreter as the keyword / constant it refers to and so no attribute lookup takes place?
The documentation says about getattr
:
Return the value of the named attribute of object. name must be a string. If the string is the name of one of the object’s attributes, the result is the value of that attribute. For example, getattr(x, ‘foobar’) is equivalent to x.foobar.
But for a reserved keyword (?) this does not hold?