Detecting Windows or Linux in code Import You can use the same if statement for import etc:
Category: Application Control
Running a python program
Run a python program from the command line
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.
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.
Auto running your program – Linux
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