tempCodeRunnerFile.py problem in visual sudio - python

I had this problem since I started using the code runner extension. a file called tempCodeRunnerFile.py get created and runs when I click on the run button it really annoying, I tried deleting the tempCodeRunnerFile.py file but it keeps coming back.

It indicates that you have selected part of the code snippet and run it.
You can add "code-runner.ignoreSelection": true in the settings.json file to avoid it.

Related

How to check if computations are done in DataSpell

I am running the following code in DataSpell
some_object = function_with_very_long_computations()
I seem not able to find any indicators in DataSpell to confirm that line execution is completed. Especially in the case where some_object already exists and I am trying to refresh it. I can surely write something new_variable = 3+5 and run it immediately after my main line and check when new_variable is populated, but this looks like an awkward solution.
Any suggestions?
If you run it within a Jupyter notebook, it'll have an indication whether the cell is still running or not.
EDIT:
For Python scripts, there is a button "Show Command Queue" on the Python Console toolbar, which displays a green dot while the script is running (see screenshot).
Not the most intuitive UI, but at least it's there.

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.

python configuration in pycharm should we need to change it every time

I ran 'hello' file code get output then I created 'xy' file and ran and get the output of 'hello' file, I know it's because of the configuration but do we need to change its interpreter every time we create a new file? or is there any better way
Right-click anywhere on your program code and click Run Your Python Program
I think you asked for this.

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.

Is there "Edit and Continue" in PyCharm? Reload code into running program like in Eclipse / PyDev?

Hi all Python developers!
In Eclipse with PyDev it is possible to edit a Python file while debugging. On save, the PyDev debugger will reload the updated code into the running program and uses my new code. How can I do the same thing in JetBrains PyCharm (using Community Edition)?
Eclipse / PyDev writes an output like this when I do that:
pydev debugger: Start reloading module: "MyWidget" ...
pydev debugger: Updated function code: <function close at 0x055F4E70>
pydev debugger: reload finished
I searched settings and web and could not find any hint. Very glad about any idea. Thx.
Edit: I found out in Eclipse/PyDev one has to be in debug mode to be able to use this feature. I tested in PyCharm, but there was no reload done.
PyCharm does not support edit and continue in either the community edition or the professional edition but here is a workaround that I have found while debugging.
Since you can run arbitrary code in the console and/or the expression evaluator, in a lot of cases, you can execute changes to the code without having to restart the application. This isn't exactly like edit-and-continue (which is a feature I really like in Visual Studio and should be part of Pycharm) but it goes a long way towards avoiding having to restart the program from scratch after a change to see if the new code works as expected.
Let me illustrate a couple of the techniques I use:
Let's say you have the following code (with a couple of typos/bugs to illustrate the techniques)
test_value = [10,9,8,7,6,55,4,3,2,1]
for i in range(0,10):
if test_value[i] == i:
print "found the value: " + i
If you run this code, first it errors because you can't print string plus integer but also I wanted to match on 5, not have 55 in the array. So here we go.
Set a break point on the for statement like this and run the code in the debugger.
When it breaks into the debugger, you realize that it should be 5 not 55. Rather than restarting, you can change line 1 to test_value = [10,9,8,7,6,5,4,3,2,1] then select the line, right click and choose Execute Line in Console... which will change the value of test_value to be the array with a 5. Now, the if statement on line 4 becomes true on the value 5. This will then trigger the syntax error on line 5.
Now if you want to make sure you have the syntax correct you can change line 5 to print "found the value: " + str(i), select the line and choose Evaluate Expression... from the right button context menu. When you click Evaluate, the result will show up either in the dialog (or in this case, since it is a print command, in the console)
Now that I've fixed these two issues, I can run the code successfully on the second pass rather than possibly multiple passes it might have taken if I didn't use these techniques. These techniques really pay off if you find a bug deep in the code where it took a while to set up.
Obviously, this is a very contrived example, but hopefully this shows how you can use both Evaluate Expression... and Execute Line in Console... to your advantage while debugging without having to restart your application each time you find a bug in the code.
Also, if you happen to be using Django, PyCharm (professional) will re-launch the server if you make changes to the code. So if you are looking at your web page and notice a problem, you can make a change to the code and switch back to the web page and as you do, either the running application or the debugged application will re-launch and the new code will be running when you refresh the page. Again, not really edit-and-continue but a pretty rapid way to make a change and test.
After all I found a useful and acceptable workaround for my question. It works in PyCharm Community Edition 3.1.2 and I assume it will do in commercial edition as well. I tested on a mid-scale project using Python 2.7.6, PySide (Qt) with one main window and 20+ widgets, tabs, whatever. Follow these steps...
Work in PyCharm on a python project :-)
Execute your code in Debug mode (did not tried Release so far)
Edit some code in one your modules imported during the life of your program
Make your program pause. To achieve this, you can click the "Pause" button of in PyCharms Debug view and then any place in your applications main window where it would need to do something (for example on a tab header). If you have a long a running task and no UI, you may place a breakpoint in a place your program often comes by.
In the Debug view, switch to the Console tab. There is a button on the left Show command line. Click this.
In the console, type in reload(MyModifiedModule) if this call fails, write import MyModifiedModule and try again.
Click resume in PyCharm.
Try the code you fixed.
There are some restrictions on this... It won't fix changes in your main method or main window, cause it won't be created again. In my tests I could not reload widgets from Qt. But it worked for classes like data containers or workers.
May the force be with you as you try this and do not hesitate to add your experiences.
I have the commercial version of PyCharm and just tried testing a simple python script. The script is the following:
for i in range(0,100):
print i
I ran the code in debug mode and placed a break point at the "print i" statement. When the debugger stopped during the first iteration I changed the code to look like this:
for i in range(0,100):
print i
print 'hello'
PyCharm did not reload/re-compile the altered script. Given this simple test my best guess would be that PyCharm does not dynamically reload .py files.
You can add hot reloading features by installing Reloadium plugin.
https://plugins.jetbrains.com/plugin/18509-reloadium
Example use (gif)
It also works without pycharm.
More details:
https://github.com/reloadware/reloadium

Categories

Resources