Home > Mobile >  Running two scripts in Python
Running two scripts in Python

Time:11-13

Dear people of the internet, I need some help... I have a Python script, main.py in which a user can enter 2 variables First, ReminderTime is an int, second, ReminderText is a string. I want to send the two variables to another Python script, reminder.py. The reminder script will do stuff with the two objects, and then it will use ToastNotifier to make a Windows notification, before shutting down. The main script will still run in the foreground during that time. Is this possible?

CodePudding user response:

You can import your other file reminder.py (make sure they are in the same path):

import reminder

And then you can run a function from reminder.py inside main.py and pass your variables:

reminder.your_function(ReminderTime, ReminderText)

CodePudding user response:

You can use multiprocessing

Simple example:

p = Process(target=f, args=(ReminderTime, ReminderText))
p.start()

f - is function in your reminder.py that will start that script (like main in main.py by default)
args - is all arguments you need to send to this function

Also, you need to import you function import reminder.function_name

This code will start you f function in background, so main code will still runing.

  • Related