Reputation: 1082
I am reading the book Python Data Science Handbook by Jake VanderPlas. In the first chapter a multi line input in IPython is illustrated:
Can anybody please tell me how to do that? I know how to write a block before executing it in Jupyter Notebook, but in the IPython shell I don't know how to do it.
Upvotes: 29
Views: 26006
Reputation: 955
thank you everybody for your answers, that pushed me to try and find mine.
i tried all the solutions above under linux, and the only one that worked for me is ctrl+o.
a new line of input is being created, though the cursor didn't move to the beginning of the newly created line.
the up and down arrows move inside of the input normally, but up on the first line loads the previous input for editing, and down on the last one loads the next.
very good for me, thank you everybody.
it is very good anyway.
Upvotes: 0
Reputation: 1335
If you type Ctrl+o, you should be able to add additional lines to the input to run them simultaneously.
If that doesn't work, as a workaround, you can paste multiple lines after copying them from elsewhere, or you can press enter on a line with a semicolon or unclosed parentheses. IPython will automatically give you another line to finish your statement rather than running and instantly hitting a syntax error.
Depending on the environment where you are running IPython, you might also want to try Ctrl+Enter or Shift+Enter.
Upvotes: 66
Reputation: 25
My suggestion is that rather using ipython shell, install jupyter notebook (pip install jupyter). then type jupyter notebook in the terminal rather than typing ipython. this command will open jupyter notebook in your default browser. here you can do whatever you want to do. you don't need have any internet connection. to stop the jupyter server, type ctrl+d in the terminal. you can watch the following tutorial on youtube: https://youtu.be/DKiI6NfSIe8
Enjoy.
Upvotes: -3
Reputation: 199
Add "<SPACE>\" at the end of the first line before hitting <ENTER>.
It allows you to enter more lines and you can remove the " \" while editing the multiline-input as well. Execute the input as described before by pressing <ENTER> in the last (empty) line, which may require pressing <ENTER> 2x at the end of the last non-empty line.
If the input already executes while pressing <ENTER> anywhere in the last non-empty line of the input you can still insert lines anywhere by pressing <ENTER> at the end of the line above and you can add a line at the end by adding "<SPACE>\" at the end of the last line as before.
For some reason none of the above methods worked for me in a cmd shell on Windows, but this did the trick.
Upvotes: 3
Reputation: 175
As an addition to the previous answers. you will need to press Enter twice to run the code. In Python 3.7.3 and maybe above, pressing enter just takes you to a new line of the multi-line ipython input. In order to run the code, press Enter again.
Upvotes: 3
Reputation: 39
Use 'shift' + 'Enter' at the end of line to avoid execution and keep typing your code. When you are done writing your block of code hit 'Enter' Have a look to the following picture If for some reason shift doesn't work, Ctrl + Enter instead. I hope this helps, good luck.
Upvotes: 3