【发布时间】:2020-08-20 22:11:56
【问题描述】:
我有一个类似的示例程序
文件.py
def test1():
print("test1")
def test2():
print("test2")
def test3():
print("test3")
def main():
sys.argv[1]
sys.argv[2]
sys.argv[3]
# test1()
# test2()
# test3()
main()
我需要执行类似“python3 File.py test1() test2() test3()”的命令
有些场景我只需要执行一两个方法只需要“python3 File.py test1() test2()”
【问题讨论】:
-
你可以为每个文件创建一个函数吗?
-
@MVB76 然后单独导入它们,确保它们都在同一个目录中
-
为什么不使用
eval? -
@impopularGuy 你能给我关于 eval 函数的详细信息吗?如何使用 eval 执行这个命令 python3 File.py test1() test2() test3()
标签: python-3.x