VS Code clear previous output before each run - python

Extensions installed: Python, Code Runner
The problem is I was trying to enable the "clear previous output before each run setting"
But when I try running a simple code the output (in terminal) becomes glitchy.
The code I am running is:
print('hello')
a=input()
print(a)
Here is the first time I run the code in completely Blank terminal
The first attempt is pretty normal.
Here is the what happens when I run the code again
There is a lot of blank space in the terminal which becomes worse the third time I run the code
This blank space worsens till the 5th attempt and here is what happens on the sixth attempt.
Basically the blank space vanishes and all the previous attempts can be seen in the terminal. But that means the initial setting I intended did not apply and terminal does not get cleared before each run.
Can someone tell how to automatically clear terminal before each run.

"code-runner.clearPreviousOutput": true works well in OUTPUT panel, but does not work in the terminal.
Someone else has submitted a feature request for it. You can refer to this page and upvote it.

Related

Step into, step over continue options hidden

I am using latest Vs code version 1.65.2. I am learning python. In my Vs code tool bar, under Run option, step into, step over continue all these options are hidden.I can run the code. But when i try to debug line by line or break point based debugging its not working. It is simply run the code and shows the error or successful run. but not able to stop the running..
I have searched and tried all possible solutions like setting break points, setting stoponenrty: ture on launch.json file, justmycode: ture, checked key board mapping debugger is current python file etc. but no resolution. If i close all the open project, still its hidden. I see i am basically missing something. but cant figure out. Appreciate your help.
Trying to debug, but step by step debug or any form of debug not not working
Let's add a breakpoint. The debugger cannot start without a breakpoint.
Then choose the debug
The order from left to right is as follows (with default vs Code shortcut):
Continue / Pause F5
Step Over F10
Step Into F11
Step Out ⇧F11
Restart ⇧⌘F5
Stop ⇧F5

SublimeRepl not syncing with code (runs old code)

I have set keybinding Ctrl+Alt+B to run code in sublimeREPL. But, recently when I run a code it wont show the last change I have made to my code. I have to first Ctrl+B and then do Ctrl+Alt+B to run properly
Code:
print("Hello")
print("added this line just now, this wont show up")
the line which was added later won't sync, it just runs the old code
Finally figured it out. I just had to turn on autosave. You can turn it on and it should be fixed. (methods are different for mac and windows, just search in youtube and everything will be alright)
Regards!

What does it mean to "restart" a program (in my case IDLE)?

This answer on Stack Overflow offers a solution I am trying to implement. In particular, see the sections "Installation Instructions" and "How to Use".
Can anyone tell me the steps required to "restart" IDLE?
New Information:
Just as people have suggested I thought this simply meant closing the program and opening it back up again...but I already tried that.
The other twist to my situation is that I'm working on a virtual machine so I was unable to do the installation of IDLE2HTML.py myself. My work's Help Desk had to do it so I cannot speak for the accuracy of their work. For now I'm assuming they did it correctly, but when I go to the "Options" menu there is no option to "Save as HTML".
My only guess at this point is that I still need to "restart IDLE".
Just wanted to double check if there was something else I could do before going back to my Help Desk department.
IDLE reads the idlelib/config-xyz.def files, including config-extensions.def, just once, when it starts. So any changes to config-extensions.def only takes effect the next time you start IDLE.
If you do not see 'Save as HTML' after starting IDLE, the extension is not installed properly.
It means you need to close the IDLE so that any changes made by the script can affect the IDLE
Simply close the IDLE either via the X, Ctrl+Q or File>Exit, then open the IDLE again.
If you are using idlelib module from a Python program then close your program and run it again.

iPython Notebook in Firefox - Warning: unresponsive script

I had a long script running on iPython notebook in Firefox for a long time. I came back and it seemed to have hung up, so I saved it and closed it.
When I re-open the script, I get a dialog box pop up with the following error:
Warning: unresponsive script
A script on this page may be busy, or it stack overflow may have
stopped responding. You can stop the script now, open the script in
the debugger, or let the script continue.
The options are 'continue', 'stop script' and 'debug script'. Clicking on any of these leads to the same result, the dialog box disappears and the iPython notebook is unresponsive (for example, ctrl+enter creates a line-break in the current cell rather than executing it).
Worst of all however, the cells at the bottom of the script seem to have been cut off. They contained some valuable code which seems to have gone, this is quite a bad outcome!
I've tried rolling back but the last roll-back point also shows the bottom cut off. Any support here much appreciated!
I have now worked this out and leave it here in the hope it will help others.
The cause of the problem seemed to be an excessively long output from one of the cells - everything below this line had been cut off in the iPython browser, but I discovered it still exists in the .ipynb file and all I had to do was remove some of the output lines, and when I re-opened the file it ran without problems AND my code that had been cut off was available once again.
The notebooks store everything in JSON format. In my case, I needed to remove output from one of the cells, which I did like this:
Browse to your iPython Notebooks directory (NOT where ipython.exe resides) - for me they were in C:\Users\myname\Documents\IPython Notebooks
Right-click on the offending notebook.ipynb file, and edit in a text editor - my choice is Notepad++
Scroll down to the cell which has generated lots of output lines. Each of these lines is inside the cell's outputs property, with "output_type": "stream"
Remove an arbitrary number of these output entries, but be sure to remove anything outside the output property itself, and be sure to remove from the back of a tailing comma to the front of the following comma so that the resulting JSON is well-formed
A typical line of output looks like this, deleting several hundred of them made my script run again in the browser:
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"Added 150000 records so far"
]
},
Maybe it's Firefox's fault.
Letting the script run longer
If you find that pressing the Continue button brings up the same dialog again, letting the script run longer won't help you; it will just make Firefox hang for longer. However, if you can use Firefox normally after pressing Continue, then the script may just needs extra time to complete.
To tell Firefox to let the script run longer:
In the Location bar, type about:config and press Enter. The about:config "This might void your warranty!" warning page may appear. Click I'll be careful, I promise! to continue to the about:config page.
In the about:config page, search for the preference dom.max_script_run_time, and double-click on it.
In the Enter integer value prompt, type 20.
Press OK.
With scripts now allowed to run for longer times, you may no longer receive the prompt.
This is from https://support.mozilla.org/en-US/kb/warning-unresponsive-script
Hope it could help.

Clearing IDLE's shell for Python

So I'm doing an MIT OCW assignment where I am creating a functional game of hangman. I got everything working. In IDLE, I have to hit F5 to run the code in the shell. I don't know any other way to run it, but that's not the big deal to me.
The main problem: the shell gets absolutely full of responses. It just keeps stacking up with more and more output. So, my question. Is it possible to put in a piece of code to clear the shell? Or do I just have to deal with it for now?
EDIT: To clarify:
I need the prints for each cycle. Every time the user guesses a letter, it prints something like this:
2 guesses remaining
Possible answers: abdfghijkpquvwxyz
Guess a letter:g
That letter is not in the word!
_ o_ _ _ tr_
I just want to know if there is a way I can clear what is in the shell before the next 'cycle' is printed.
You can close it and just open a new one when you want to run the program or run it from the terminal and use use clear after you exit the shell

Categories