Auto-running a Python file within a terminal window See our page here. Auto running a program with auto restart on crash See our page here. Make the .sh file executable and then run it. To forcibly exit use: CTRL+C
Category: Application Control
Detect Windows vs Linux
Detecting Windows or Linux in code Import You can use the same if statement for import etc:
Exiting a python program
Exit an endless loop Python program This method uses an interrupt to capture keyboard CTRL+C entered on the command line, but then cleanly exits from the program’s main loop.
Getting command line arguments
Get arguments Returned as a list, index 0 being the path + filename of the python file that has been run Get argument and its value This example forces to lower case, remove .lower() if you don’t want that
Making a python file executable
#!/usr/bin/python If the script is made executable, the operating system will use that first line to know which interpreter to run to parse the rest of the file. If you always run python scripts from the command line like python myprogram.py then you could remove this line if preferred.
Running a python program
Run a python program from the command line