Skip to content

Commit

Permalink
bpo-20692: Add Programming FAQ entry for 1.__class__ error. (GH-28918)
Browse files Browse the repository at this point in the history
To avoid error, add either space or parentheses.
  • Loading branch information
terryjreedy authored Oct 13, 2021
1 parent 678433f commit 380c440
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Doc/faq/programming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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?
--------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add Programming FAQ entry explaining that int literal attribute access
requires either a space after or parentheses around the literal.

0 comments on commit 380c440

Please sign in to comment.