[英](Multithreading-Python) How I can create a script that run two scripts which I usually run from two different terminals?
[英]How can I run 3 functions in python from a different script?
我在 python 脚本中有 3 个函数,我想同时运行它们,但来自另一个 python 脚本,例如:
def a():
print("\nphrase1")
def b():
print("\nphrase2")
def c():
print("\nphrase3")
我想从不同的文件中运行这 3 个函数。 有人可以支持我吗?
我建议您将具有这些功能的程序复制到与您要运行它们的程序相同的文件夹中
from yourprogram import a, b, c
#code
a()
b()
c()
假设如果 function 以上的所有内容都在模块fun.py
,那么使用下面的代码片段来运行所有这些 -
import fun
for i in dir(fun):
item = getattr(fun,i)
if callable(item):
item()
dir(fun) 检索模块 fun 的所有属性。 如果属性是可调用的 object,则调用它。 请注意,它将调用 fun 模块中可调用的所有内容。
希望这能回答你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.