summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-10-12 22:37:51 -0700
committerGitHub <noreply@github.com>2021-10-12 22:37:51 -0700
commit47673c47db352916384e4f35fa520e48475e2601 (patch)
tree98b77d08c35e17a5337fc3309f2dc4f784172691
parentedae3e2ac73151217b4b4e096dd9f17cc0a50c11 (diff)
downloadcpython-git-47673c47db352916384e4f35fa520e48475e2601.tar.gz
bpo-20692: Add Programming FAQ entry for 1.__class__ error. (GH-28918)
To avoid error, add either space or parentheses. (cherry picked from commit 380c44087505d0d560f97e325028f27393551164) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
-rw-r--r--Doc/faq/programming.rst21
-rw-r--r--Misc/NEWS.d/next/Documentation/2021-10-13-00-42-54.bpo-20692.K5rGtP.rst2
2 files changed, 23 insertions, 0 deletions
diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
index ef80808a1a..12b70dbbe7 100644
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -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?
--------------------------------------
diff --git a/Misc/NEWS.d/next/Documentation/2021-10-13-00-42-54.bpo-20692.K5rGtP.rst b/Misc/NEWS.d/next/Documentation/2021-10-13-00-42-54.bpo-20692.K5rGtP.rst
new file mode 100644
index 0000000000..44ae468d1b
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2021-10-13-00-42-54.bpo-20692.K5rGtP.rst
@@ -0,0 +1,2 @@
+Add Programming FAQ entry explaining that int literal attribute access
+requires either a space after or parentheses around the literal.