bpo-20692: Add Programming FAQ entry for 1.__class__ error. (GH-28918)

To avoid error, add either space or parentheses.
This commit is contained in:
Terry Jan Reedy 2021-10-13 01:14:58 -04:00 committed by GitHub
parent 678433f25e
commit 380c440875
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View file

@ -836,6 +836,27 @@ ago? ``-190 % 12 == 2`` is useful; ``-190 % 12 == -10`` is a bug waiting to
bite.
How do I get int literal attribute instead of SyntaxError?
----------------------------------------------------------
Trying to lookup an ``int`` literal attribute in the normal manner gives
a syntax error because the period is seen as a decimal point::
>>> 1.__class__
File "<stdin>", line 1
1.__class__
^
SyntaxError: invalid decimal literal
The solution is to separate the literal from the period
with either a space or parentheses.
>>> 1 .__class__
<class 'int'>
>>> (1).__class__
<class 'int'>
How do I convert a string to a number?
--------------------------------------

View file

@ -0,0 +1,2 @@
Add Programming FAQ entry explaining that int literal attribute access
requires either a space after or parentheses around the literal.