Reputation: 25
I have 3 functions in a python script that I would like to run at the same time but from another python script, for example:
def a():
print("\nphrase1")
def b():
print("\nphrase2")
def c():
print("\nphrase3")
I would like to run those 3 functions from a different file. Could anyone support me on that?
Upvotes: 0
Views: 101
Reputation: 574
Suppose if all above function is inside module fun.py
then use below code snippet to run all of it -
import fun
for i in dir(fun):
item = getattr(fun,i)
if callable(item):
item()
dir(fun) retrieves all the attributes of module fun. If the attribute is a callable object, call it. Just a note, it will call everything which is callable in the fun module.
Hope this answers your question.
Upvotes: 1
Reputation: 28
I suggest you copy the program with the functions to the same folder as the program you want to run them
from yourprogram import a, b, c
#code
a()
b()
c()
Upvotes: 1