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
Related
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.
I am curious if it possible to make custom terminal commands for a Python application, for example, if I were to make a slideshow program, one could into the command line INDEPENDENTLY from the program and type
C:\Users\foo> Slides
And get
SLIDES v0.0.0 Example
Example command, example command
And if you typed
start unnamed.slides
The slide program would open up and run slide project “unnamed”.
Please ignore any factual errors in this if it were the actual commands for a program I’m just trying to get a point across.
You might want to take a look at the Argparse library that allows you to have command line options that are easily manageable. You can then use these options to execute certain parts of you program.
All you need to do is use terminal input functions inside a while loop with code that responds to the input accordingly. To put it simply it would be like this:
while True:
user_input = input('command: ')
# do whatever with the user input here.
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.
I wrote a program in my editor and clicked run(F5). Afterwards, in the python shell, I keyed in the desired inputs. What should i do next to make it start running? Attached picture is python editor and python shell.
Thanks!
Use CTRL-D to stop entering new sys.stdin.read() input. Also don't use this.
https://teamtreehouse.com/community/whats-the-difference-between-sysstdinread-and-input
I am building a datalogger for a group of PV inverters using Raspberry Pi and am using two python scripts to collect the data over two separate communication protocols. I need to change two variables in each script if I move from one site to another - the first and the last inverter id for the new site.
I want to make this change user friendly such that a new user does not have to open the python script to change the values. So I want to have an executable program in linux environment (which may have an icon on the Pi desktop) which the user can open and it will prompt to specify first and last inverter id and transfers this change to python script. If this is too complicated to achieve for this task, maybe a simple command for the terminal window which will prompt the same changes??
I hope the task is sufficiently explained. I am not a programmer by trade and am doing this project as a hobby, so please forgive me if I am ignoring something obvious :|
Just posting a successful update for this query. The desktop configuration file method was the simplest and it worked. I wrote the following in the .desktop file
[Desktop Entry]
Version=1.0
Name= ProgramName
Comment= my comment
Exec=sudo python /usr/share/app/app.py
Icon=/usr/share/pixmaps/geany.xpm
Path=/usr/local/lib/python2.7
Terminal=true
Type=Application
Categories=Utility;Application;
I added the "python" bit to the Exec line and hence did not have to write a she-bang line in the script. Also the Terminal option had to made True since I needed a prompt for the user to enter a value.
Hope this helps somebody else.