I have a python program which takes an input (a single character, 'y' or 'n') from the user and then executes a certain task based on that input. My need is to allow this program to run continuously from the terminal until I decide to stop it. Currently, I have to keep going back to the terminal and execute the program from there (and always type in that single character).
PS: If it helps: the program adds data to a MySQL
database, so I need this in order to make the whole process automated (and thus a bit quicker)
EDIT
My my-program.py
looks like this:
main():
if input().lower()=='y':
#does something here
else:
#does something else
My requirement was to run a Python program infinitely from the Terminal. I do know how to use loops and how to perform tasks based on user input. What I wanted was to automatically give 'n' as the input character input whenever prompted.
my-program.py
performs a certain operation when a character is given as input. When i call my-program.main()
from another Python program using a while loop as below, I want to keep passing the same input (say 'n'
) whenever prompted (when the input()
statement of my-program.py
is executed)
import my-program
while True:
my-program.main()