Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError when pasting multiple lines in Python [duplicate]

Tags:

python

I'm having trouble copy-pasting code in Python. Say I have the following code I want to paste into a Python interpreter:

string_one = "Help"
string_two = "Me"

Locally, running 3.8.5 on a Mac OSX 10.15.7, if I paste that code, I get SyntaxError: multiple statements found while compiling a single statement.

However, if I ssh into another machine, open up Python (3.7.4), and paste those two lines, I get no error. Also, when I paste those two lines into a Python 2.7.16 shell, I get no error. What could possibly be the problem here?

Python 3 (problem shell) enter image description here

Python 2 (non-problem shell) enter image description here

like image 276
pete Avatar asked Jan 08 '21 22:01

pete


People also ask

How do I paste multiple lines of code in Python shell?

IdleX provides the PastePyShell.py extension for IDLE which allows pasting of multiple lines into the shell for execution.

How do you type multiple lines in Python Mac?

The shortcut to comment multiple lines in Python and PyCharm are: Windows or Linux: Ctrl + / Mac OS: Command + /

How do you copy and paste code in Python?

To copy text, just select it and hit Ctrl-C (Command-C on a Mac). If the highlight marking the selection disappears, that's normal and it means it's worked. To paste, use Ctrl-V (Command-V on a Mac).


Video Answer


1 Answers

It seems that there is a bug in readline (which is used by Homebrew to install python)

Short answer:

echo "set enable-bracketed-paste off" >> ~/.inputrc

Long answer: https://github.com/Homebrew/homebrew-core/issues/68193


(This was erroneously edited into the question; I have rolled back that edit, and am pasting the solution as an actual answer instead, and tagging as Community Wiki.)

like image 153
tripleee Avatar answered Oct 18 '22 23:10

tripleee