Can you make an auto-executable script in Python? (Autorun)

Asked

Viewed 637 times

2

Hello, I’m starting to learn Python, I know only the basics, I wanted to make a script self executable (autorun), but I searched all over the internet and I couldn’t find anywhere to do an autorun in Python, so is there any way to do this? If yes, could someone explain how and leave an example code for me see how it works? I thank you for the answer

By the way, preferably in Python 3

  • You can define what is an auto-executable script?

  • It would be for example a script already after compiled, which starts automatically, when I plug a pen drive into the machine for example

  • depends on the operating system, but in any case this script will need to be a service that runs when such an event occurs on the operating system. In case you need to find a library that does this and turn your script into a service.

  • Ah understood, maybe it’s easier then I leave by Java

1 answer

-1

One of the options would be to use a Job Scheduler, briefly it will schedule a task(job) and when your time comes, will be executed, can repeat or not, depends on how you scheduled the task(job).

Ex of a lib:

import schedule
import time

def job():
    print("I'm working...")

schedule.every(10).minutes.do(job)
schedule.every().hour.do(job)
schedule.every().day.at("10:30").do(job)
schedule.every(5).to(10).minutes.do(job)
schedule.every().monday.do(job)
schedule.every().wednesday.at("13:15").do(job)

while True:
    schedule.run_pending()
    time.sleep(1)

Get a general introduction about.

Schedule - Python job Scheduling for Humans.

A list of them implemented in python

Browser other questions tagged

You are not signed in. Login or sign up in order to post.