Skip to content

Commit cc90732

Browse files
bpo-20692: Add Programming FAQ entry for 1.__class__ error. (GH-28918)
To avoid error, add either space or parentheses. (cherry picked from commit 380c440) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
1 parent 9901d15 commit cc90732

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

Doc/faq/programming.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,27 @@ ago? ``-190 % 12 == 2`` is useful; ``-190 % 12 == -10`` is a bug waiting to
836836
bite.
837837

838838

839+
How do I get int literal attribute instead of SyntaxError?
840+
----------------------------------------------------------
841+
842+
Trying to lookup an ``int`` literal attribute in the normal manner gives
843+
a syntax error because the period is seen as a decimal point::
844+
845+
>>> 1.__class__
846+
File "<stdin>", line 1
847+
1.__class__
848+
^
849+
SyntaxError: invalid decimal literal
850+
851+
The solution is to separate the literal from the period
852+
with either a space or parentheses.
853+
854+
>>> 1 .__class__
855+
<class 'int'>
856+
>>> (1).__class__
857+
<class 'int'>
858+
859+
839860
How do I convert a string to a number?
840861
--------------------------------------
841862

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add Programming FAQ entry explaining that int literal attribute access
2+
requires either a space after or parentheses around the literal.

0 commit comments

Comments
 (0)