I was previously using the Jupyter extension for VS-code (https://github.com/DonJayamanne/vscodeJupyter) and could select my code and run it with the output being displayed in a 'Results' pane.
This no longer seems to work - when I for instance select a variable and run it the "Python 3 Kernel" status at the bottom flicks rapidly between busy/idle, but the variable is not displayed.
I see that the extension is now deprecated and instead one can run cells using the python extension, however is there any way to replicate this old functionality which was quite central to my workflow?
So we actually just added this functionality to the Microsoft Python Extension and it just shipped last night. If you are in a .py document with #%% cells defined you can hit shift+enter in a cell with no text selected to run that cell in the Interactive Windows. If you are in a .py file with cells defined and you selected text and hit shift+enter then just that text (not the whole cell) will get sent to the Interactive Windows. If you are in a .py file without cells defined and you select text and hit shift-enter that text will get sent to the normal python terminal as before. But you will now see a one time pop-up asking if you would instead like to send shift-enter commands in non-cell files to the Interactive Window instead. If you miss the pop-up you can also just change the Send Selection to Interactive Window command that we had added in the options.
Related
Is there any way to disable auto clearing console in Pycharm? right now each time that we run the pycharm it clears up the console (run tool window) automatically! I need to have the history of my results
If you want to keep the history of the results, consider writing the output to a file instead of the console.
If you prefer writing to the console (perhaps that's the aim of the application), you can also change the Run Configuration for your script.
In the Run menu, under Edit Configurations..., select the run configuration for your script and select the Logs tab (it shows the Configuration tab by default). On there, you'll find a checkbox to Save console output to file; set a file name in the field next to it.
Currently, PyCharm doesn't have an option to add a timestamp to a filename like this (although the feature has been requested by users, so it may in the future). So, you could add a few lines of code to the start of your program that only runs when debugging, moving the previous output file out of the way of for the new output.
In previous versions of Spyder, you can select lines in the editor, and only run those selected lines.
In Spyder 4, when you select lines and press Ctrl+Enter it executes runcell(0, '/your/dir/file.py') which runs the whole code.
How can I run just the lines which I have selected?
The hotkey for running a the line at which the cursor is, or the currently selected lines in Spyder 4 is F9. Ctrl+Enter will run the current cell. You can read more about cells in Spyder here. Basically, these are blocks of code that can be defined in the editor using a specific syntax within the code, and can be run independently by Spyder and other IDEs.
Incidentally, Ctrl+Enter is the keyboard shortcut for running the current line in R Studio, not Spyder, which may be where you got it confused.
In Spyder 4.0.1, the keyboard shortcut for 'run cell' is set to Ctrl+Return but for 'run selection' it is set to F9. You can use F9 to run a selection or if you prefer to use Ctrl+Return, you can go to Tools -> Preferences -> Keyboard shortcuts. Search for 'run selection', double click and set Ctrl+Return as the 'New shortcut'
In Spyder, you can organize your code as runnable cells
Use the the pattern # In[] or #%% to define the start of a cell. You can also have child cells by adding additional percent signs %
In Spyder 4 the keyboard shortcut to run the highlighted lines of code is F9. and if you want to use any other shortcut then you can change it from TOOLS>>PREFERENCES>>KEYBOARD SHORTCUTS then double click on any shortcut you want to change and change with your shortcut. but be very careful if you used the same shortcut that is used for any other work then for that it will remove.
Apologies in advance for what should seem obvious to me...
New to Python, but other wise very experience, hence the frustration.
As I'm learning, I'm attempting to prototype the command at the command prompt (">>>") as I script. I can enter the python commands and validate they are correct, but (currently) then have to retype the command in to sublime, which seems inane, especially as I'm watching videos where they are copying and pasting one to the other...
Windows 7 CMD, & Python ">>>" command lines, Sublime window
I'm trying to copy commands from the Python command line ">>>" to the sublime editor in an open/new tab. Normally, I would mark/highlight the selection, then Ctrl+c, place the cursor in the target window (sublime in this case), Ctrl-v, and be done.
However, I'm unable to select what I want to copy (??). Up/down arrows will recall the individual lines (no problem with that) -- where I would usually do a Ctrl-(left/right arrow) to select the text, but no indication that anything has been selected. Same result using the mouse.
Thanks in advance for the assist.
This is an oddity of the Windows command prompt. First, there is a little bit of setup. Then you can do the cut-and-paste in a slightly different way than you are used to.
Setup
Right click on the title bar at the top. Select "Properties". Click on the "Options" tab. Make sure that the "QuickEditMode" box is checked. Close the Properties window.
Cut-and-paste should be enabled, but not using control-C to cut. Select the text you want to copy. Instead of typing control-C, just hit return (with the desired text selected). The text should now be on the clipboard to paste into other applications (with control-V)
In Linux terminals, pressing Ctrl+k copies everything in the line that follows the cursor. Ctrl+u copies the everything before the cursor.
In Spyder I can run only a part of code without running everything. I know that in PyCharm I can click right mouse button and "Execute Selection in Console", but it will be new execution without values and variables which declared before this part of code.
So, very often I need to run only few last lines of my code, with parametres and options that I already have.
you can try to use the interactive interpreter while in debug mode.
I find it to be very useful when trying to run code snippets in the program.
view the screenshot below.
You can use the "Run cell" functionality and the cell will be executed in the Python Console (the same way it does when right clicking "Execute Selection in Console"). To enable that I am aware of two options :
In settings (Ctrl+Alt+S) install the "PyCharm cell mode" plugin.
Then use ## to create code sections.
https://plugins.jetbrains.com/plugin/7858-pycharm-cell-mode
Create a new project in scientific mode (only available in PyCharm professional)
You can create code cells with #%%.
https://www.jetbrains.com/help/pycharm/matplotlib-support.html
In both cases, it creates cells that you can execute with the green "play" button like shown below :
How to print the entire python idle commands history to a text file. For example the list of commands I already typed
One prints the contents of a Shell window the same as an editor or output window. Select File and then Print Window and then OK. Or use the shortcut key, which on Windows, at least, is Control-P. I verified that this works on Windows with 2.7.13 and 3.6.1.
One can also save Shell content with File, Save As and then edit the result. Then print if one wants a paper copy.
https://bugs.python.org/issue11838 is about making it easier to get running code from a shell log. One problem with saving just the user input is that it loses the bug information in tracebacks.