我有一个正在处理一系列动作的循环:
# ask user to set up search filters
While True:
user_input_filters = input("Set up filters and type 'go' to continue")
if user_input_filters != "go":
print("Type 'go' to continue")
continue
else:
if user_input_filters =="go":
user_input_filters = False
break
bol_start_tool = False
# request user input start
While True:
user_input_start = input("Press ENTER to start")
if user_input_start != "":
print("Press ENTER!")
continue
else:
bol_start_tool = True
break
# actual start of PROCESS
if bol_start_tool:
# MY CODE FOR PROCESS (searching according to the filters and further on working with the results)
#..
#...
#....
开始#MY CODE的部分...被无限次重复,
我需要找到一种方法,使用户有机会停止该过程并重新启动该过程。
重新启动应从“#要求用户设置搜索过滤器”开始,因为通常在用户要停止以更改其搜索过滤器时会出现这种情况。
[当前,我不使用GUI(已打通),所以我考虑设置两个用户输入选项,一个用于停止,另一个用于重启。
我在chromedriver中使用硒,因此无法完全关闭程序并手动重新启动不是解决方案。从那时起,用户每次想在过滤器中进行更改时都必须重新登录等。
有什么办法,我可以在代码中实现这两个功能吗?
或者您对我将如何重新编写代码以使其正常工作有任何建议吗?
非常感谢您的帮助。
您需要全局while循环
need_to_stop = False
While !need_to_stop:
# ask user to set up search filters
While True:
user_input_filters = input("Set up filters and type 'go' to continue")
# ***
bol_start_tool = False
# request user input start
While True:
user_input_start = input("Press ENTER to start")
# ***
# actual start of PROCESS
if bol_start_tool:
# MY CODE FOR PROCESS (searching according to the filters and further on working with the results)
break; # <- this is your solution