Execute multiple lines of code at once
See original GitHub issueHi, I am trying to execute multiple lines of code using ipython 6.0.1 (I also have tried 6.0.0) but cannot find any shortcut working (i.e. alt + enter or shift + enter) to get a new line. I am not sure if this is a bug or if I am missing something? For example if I want to write and execute these multiple lines of code at once:
In [5]: import numpy as np
...: a = np.array([1])
...: print(a)
...:
[1]
At the moment I need to explicitly write the backslash operator to get a new line, i.e.
In [4]: import numpy as np \
...: a = np.array([1]) \
...: print(a)
and then remove manually the backslash operators to make it run as in the first example, otherwise ipython is complaining:
In [6]: import numpy as np \
...: a = np.array([1]) \
...: print(a)
File "<ipython-input-6-b0ea1b71283b>", line 1
import numpy as np a = np.array([1]) print(a)
^
SyntaxError: invalid syntax
I have tried 2 different terminals but get the same problem. Any help would be appreciated!
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to Execute Multiple Lines in a Single Line Python From ...
Summary: To make a Python one-liner out of any multi-line Python script, replace the new lines with a new line character '\n' and...
Read more >dHow to execute multiple lines of code, Python, Selenium
I have all the webscraping done, all the send_keys done. I just want to be able to execute multiple lines of code as...
Read more >How do I run a multi-line Python script in IDLE? - Quora
Python, writing multi line code in IDLE, Try File => New Window in top menu. Then write your code in this windows and...
Read more >Enter Multiple Lines Without Running Them - MatLab
To enter multiple lines before running any of them, use Shift+Enter or Shift+Return after typing a line. This is useful, for example, when...
Read more >How to Comment Out Multiple Lines in Python - freeCodeCamp
Apart from making your code more readable, comments can also help ... two lines of code, you can comment out one to prevent...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
There is a trick you can use. You can use parenthesis in the beginning of the code-block you want to write, when hit enter-key, it will automatically add lines to your command meanwhile the parenthesis in the beginning is not closed. Before executing you must remove parenthesis. Another common way it’s if you have a block defined by after ‘:’, everytime you hit enter-key it will add conforming the identetion of the block (which is nice if you need to write and execute a for loop). If you add a line with any of these manners and in the final line you hit enter (and this line is empty and all parenthesis previously closed if any) it will execute the whole block you wrote without problems. You can try and discover many other ways. But it’s possible. You don’t have to argue with one-line convention if needed a multiple-line execution or block one
Thanks, I see. I thought it was something I was missing as it is what is shown on the main documentation in the picture: https://ipython.readthedocs.io/en/stable/_images/ipython-6-screenshot.png
In the meantime I have found out a shortcut that is somewhat working (in my settings ?) which is ctrl+o. This actually starts a new line (with the 3 dots ‘…’), except the cursor is staying at the same place and I need to press the arrow key to put the cursor on the new line. This is not the best but still better than the backslash!