Disable Auto-clearing console (run window) in Pycharm - python

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.

Related

How to debug breakpoint in pycharm at the end of file without adding a dummy line?

Normally, if I want to run a python file beginning-to-end in pycharm, but stop at the end so I can see all the variables etc., I add a line at the end of the file like
justadummyvar = 3
And attach a breakpoint to it.
Is there a way to just tell pycharm to debug run the file and stop at the end before flushing memory so I can get the same effect without changing the file contents?
The thing I was looking for is to right click within the editor and select Run File in Python Console. From there, you can see variables stored in memory and issue new commands after the entire script runs.
You can re-run or run with debug with the buttons on the left of the little console window.

How to stop the display of two terminal 'summaries' in VS Code on Macos?

I am using VS Code to program in Python, but was running into an issue, VS Code was using the current open folder as the active directory instead of the directory the file was in. Therefore, I went into my settings.json and changed "python.terminal.executeInFileDir": from false to true. However, what this ended up doing is navigating to the open folder, and then navigating to the file's directory every time I ran the file in the terminal. You can see this in the screen shot below.
Screenshot of my code editor page.
As you can see, every time I run the file, it prints the first snippet/ summary:
ishaanbhagat at Ishaans-Macbook in test
$ cd "/Volumes/GoogleDrive/My Drive/Personal/Programming/Ishaan's Python/test"
and then in the following line the second snippet/ summary:
ishaanbhagat at Ishaans-Macbook in test
$ /usr/local/bin/python3 "/Volumes/GoogleDrive/My Drive/Personal/Programming/Ishaan's Python/test/test.py"
hello
I would only like it to display the second snippet of text or summary, which as you can see is the only one which actually prints the output of hello. The first snippet is redundant, and distracts me by taking up a lot of space on my terminal. Could anyone help me with this?
TL, DR: As you can see in the screenshot, my VS Code terminal is displaying a summary twice, with the second one being the only 'useful' one. I would like the terminal to only display the second summary. Thank you very much
When I set 'python.terminal.executeInFileDir' to false, the terminal only displays the second part of what you said.
If you just want the console information to be concise, you could refer to the following methods:
Set '"console": "integratedTerminal"' in the launch.json file, the running result will appear in a separate cmd window, and only the result will be displayed.
Try to download an extended application that can provide related functions in the VSCode extension store, for example: Code Runner;
More references:Integrated Terminal and setting.

Run selected lines and show output using jupyter notebook

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.

How to run only block of code in PyCharm like in Spyder?

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 can I run my currently edited file in a PyCharm console in a way that I can type into the command line afterwards?

I want this so I can retain the command line history after repeated runs, and to paste lines from the console into tests etc. Exactly like in IDLE.
[I realize this question is basically a duplicate of Running a module from the pycharm console. But the question there is not answered satisfyingly (for me), and my lack of reputation does not let me comment there, since I just signed up.]
Shift+Alt+Ewould execute the selected code.
Select the code fragment or the entire file, then use Execute Selection in Console from the context menu.
For anyone still having this problem: Go to the Run/Debug menu, choose Edit Configuration, check the box 'Show command line' this will enable you to enter parameters in the console at the >>> prompt and test your function.
Edit: To make this change apply to all your .py files (as this check box only applies to the current file you're working on) go to: Edit configuration, in the pop up you will see a menu tree on the left, select Defaults, then Python, then check the 'Show command line' box, this will make it the default setting whenever you open a .py file, (this feature should really be on by default!)

Categories

Resources