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

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.

Related

tempCodeRunnerFile.py problem in visual sudio

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.

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.

How to gather data from a file and execute a Python file using it via right click?

This title is a bit confusing but let me explain. So say you have a file called test.txt. If you right click on it, it will most likely have a menu appear and will say stuff like "Open in Notepad". How can I get a python file to show in that menu so that it could say "Open in program.py" and the program would run and for example
print(data)
input()
Data being the contents of test.txt. Does anyone know if this is possible?
You need to edit the registry entries in Windows. See this to how.
You have to replace the path with your own script such as C:\\Program Files\\Something\\YourPythonScript %1
%1 represents the associated file name.
Edit: In your python script, you can use sys.argv in order to retrieve the file name of the associated file and process on it.
import sys
#Get selected file
filename = sys.argv[1]
you can use other programs to open your foo.py python code. but that program can't execute the code directly just by one click right. you have to open in program that can run python codes and run the code there.
hope this help you.

How to initiate python program with a change in the input?

I have an application made in python, this application takes input from a separate text file called input.txt, i have to design the application in such a way that application runs automatically with any input to input.txt. Such that i need not go to command prompt and run the program, if i give the input, or change the text present in input.txt, python program should start execute automatically.
Please help me out with this :)
Thank you :) :)
You can run your program once and watch the filesystem changes for new or modified file. Try using python-inotify for linux:
https://github.com/seb-m/pyinotify

Categories

Resources