Sample Header Ad - 728x90

Copy & paste Python code into the command line

1 vote
1 answer
2218 views
When I paste several lines at once in a Python3.9 session in the terminal in my Mac it does not understand that they are different lines, and it fails:
Python 3.9.1 (default, Jan  8 2021, 17:17:17) 
[Clang 12.0.0 (clang-1200.0.32.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 7
b = 3
a + b
  File "", line 1
    a = 7
b = 3
a + b

         ^
SyntaxError: multiple statements found while compiling a single statement
But the funny thing is that if I do it in a Python2.7 it goes well:
Python 2.7.16 (default, Jun  5 2020, 22:59:21) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 7
>>> b = 3
>>> a + b
10
I would think that there is something in my environment or bash_profile but why it fails only in the 3.9 version? Thanks in advance. Miguel.
Asked by miguelbadajoz (111 rep)
Jan 26, 2021, 09:06 AM
Last activity: Apr 28, 2025, 01:00 AM