run automatically a program every minute in python

To run a program every minute in Python, you can make use of the time module and schedule the execution of the script using a job scheduling library like cron in Unix-based systems.

Here is an example code snippet that prints out the current time every minute:

main.py
import time

while True:
    print("Current time:", time.strftime("%H:%M:%S"))
    time.sleep(60)  # wait for 60 seconds before executing again
144 chars
6 lines

To automate the execution of the above Python script every minute, you can use cron in Unix-based systems. By using the following command in the terminal, you can edit the cron job configuration:

crontab -e
11 chars
2 lines

Then add the following line to the cron configuration file:

* * * * * path/to/python /path/to/script.py
44 chars
2 lines

This cron job configuration will execute the Python script located at /path/to/script.py every minute (* * * * * specifies the time interval) using the python command. Make sure to replace path/to/python with the path to your Python interpreter if it's different.

gistlibby LogSnag