python_wiki:main_program_loop

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

python_wiki:main_program_loop [2015/03/09 23:26]
billdozor
python_wiki:main_program_loop [2019/05/25 23:50]
Line 1: Line 1:
-====== Main Program Loop ====== 
  
-**General Information** 
- 
-This is an example of a main program loop, wrapped in a try command to catch keyboard interrupts. 
- 
-**Checklist** 
-  * Modules required: signal (keyboard interrupts) 
- 
----- 
-===== The Code ===== 
- 
-<code python> 
-import signal 
- 
-def main(): 
-# Main program loop: Until quit is detected, ask user what to do 
-  while True: 
-    # Display Main Menu and get user input 
-    # wrap the "try" command to prevent a ctrl+c to break out of the program 
-    try: 
-      menu_choice = main_menu() 
-  
-      if menu_choice == "quit": 
-        # Quit from main menu. 
- print("Quitting program...") 
- break 
-  
-      else: 
- # Send Menu Choice to run_program 
- run_program(menu_choice) 
- continue 
-  
-    #trap keyboard interrupts (control+c), quit clean only 
-    except (KeyboardInterrupt): 
-      input("\nPlease quit by entering 'q' or 'quit'! [Enter] to continue:") 
-      continue 
-  # END OF WHILE LOOP  
-  return 0 
-## End of main() ## 
-</code> 
  • python_wiki/main_program_loop.txt
  • Last modified: 2019/05/25 23:50
  • (external edit)