An application loop repeatedly shows the available actions, accepts a user choice, runs that action, and waits before returning to the menu. It keeps an interactive program usable for several actions while leaving the menu’s exit option in control. section 6.3.3
A small application loop
def loop(): print_options(options) chosen_option = get_option_choice(options) chosen_option.choose() input('Press ENTER to return to menu') while True: loop() section 6.3.3
A practical loop coordinates these steps:
- Present menu options connected to commands. section 6.3.3
- Validate the user’s choice and select the matching option. section 6.3.3
- Clear the screen, run the chosen action, and pause before the next menu. section 6.3.3
def loop(): #1
# All the steps for showing/selecting options
...
_ = input('Press ENTER to return to menu') #2
if __name__ == '__main__':
commands.CreateBookmarksTableCommand().execute()
while True: #3
loop()
Shows the loop method, the pause returning users to the menu, and the outer repetition. section 6.3.3
