扫描一个目录创建了选定的脚本列表,放入列表中,然后一个人执行它们
我对SW编码的新手需要一些帮助。谢谢你!
- 的菜单格式显示它
- 并使用枚举
- 有一个脚本可以扫描.py文件的路径,
我 问题是它仅从用户选择的列表中运行拳头选定的文件。这是我的简单代码。
import os
import sys
choice_1 = ''
run_list = []
while choice_1 != 'q':
print("\nPlease select desire test case: ")
items = os.listdir("C:/Users/tonp\PycharmProjects/untitled1")
fileList = [name for name in items if name.endswith(".py")]
for cnt, fileName in enumerate(fileList, 0):
sys.stdout.write("[%d] %s\n\r" % (cnt, fileName))
choice = int(input("Select from [1-%s]: " % cnt))
choice_1 = input("Press any key to add more case or q to start running testsuite ")
run_list.append(fileList[choice])
print("These are the case/s you have selected so far :")
print(run_list)
selected_files = run_list
for x in run_list:
exec(open(c).read())
I am very new to sw coding needing some help. Thank You!
- I have a script that scan a path for .py files and display it it in menu format using enumerates
- Ask user to select file/files they want to run and put them in a list
- And start ran those file from this list one by one
My issue is that it only ran the the fist selected file from the user selected list. Here is my simple code.
import os
import sys
choice_1 = ''
run_list = []
while choice_1 != 'q':
print("\nPlease select desire test case: ")
items = os.listdir("C:/Users/tonp\PycharmProjects/untitled1")
fileList = [name for name in items if name.endswith(".py")]
for cnt, fileName in enumerate(fileList, 0):
sys.stdout.write("[%d] %s\n\r" % (cnt, fileName))
choice = int(input("Select from [1-%s]: " % cnt))
choice_1 = input("Press any key to add more case or q to start running testsuite ")
run_list.append(fileList[choice])
print("These are the case/s you have selected so far :")
print(run_list)
selected_files = run_list
for x in run_list:
exec(open(c).read())
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要使用 importlib。
检查此链接以获取可能对您有帮助的答案:
退出导入的模块而不退出主模块程序 - Python
要允许用户根据需要退出,您可以在 while True 内执行类似的操作:
You may need to use importlib.
Check this link for an answer that might help you in this direction:
Exit an imported module without exiting the main program - Python
To allow the user to exit as needed you can do something like this inside the while True: