使用标志变量从另一个python脚本执行python求解器
我目前正在使用Python Pipline工作,在该管道中,我需要从Python代码调用不同的求解器/脚本并执行它们。由于将涉及不同的代码,因此我想根据标志参数称这些求解器为其称为这些求解器,并相应地运行它们。以下是我打算做的示例:
因此,有两个或多个Python代码,通常具有100行代码,但是在这里我以通用的示例
#script1.py
import numpy
def test1():
print('This is script One')
if __name__ == '__main__':
test1()
#script2.py
import numpy
def test2():
print('This is script two')
if __name__ == '__main__':
test2()
从另一个脚本main执行了一个通用示例。 py
使用
#main.py
import numpy
from script1 import *
from script2 import *
if __name__=='__main__':
test1()
test2()
此main.py
执行我不想要的两个。我想使用标志变量并执行我需要的任何一种。可以使用argparse
命令行解析完成此操作吗?因为每个script.py
在它运行中可能会有更多标志。那也是我更喜欢的东西。
谢谢
I'm currently working on a python pipline where I need to call different solvers/scripts from a python code and execute them. Since there would be different kind of codes involved, I would like to call these solvers based on flag parameters and run them accordingly. Below is an example of what I intend to do:
So there are two or more python codes, typically with 100s of lines of code, but here I have taken a generic example
#script1.py
import numpy
def test1():
print('This is script One')
if __name__ == '__main__':
test1()
#script2.py
import numpy
def test2():
print('This is script two')
if __name__ == '__main__':
test2()
At the moment I execute them from another script main.py
with
#main.py
import numpy
from script1 import *
from script2 import *
if __name__=='__main__':
test1()
test2()
This main.py
executes both of them which I don't want. I would like to use flag variables and execute them whichever I need to. Can this be done using argparse
command line parsing ? As there might be further flags in each script.py
for it to run. That would be something I prefer as well.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做类似的事情:
现在您可以执行测试
You can do something like:
Now you can execute your tests as