Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
python_wiki:main_program_loop [2014/11/19 22:18] billdozor created |
python_wiki:main_program_loop [2016/11/30 22:08] billdozor |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Main Program Loop ====== | ====== Main Program Loop ====== | ||
+ | |||
+ | **General Information** | ||
+ | |||
This is an example of a main program loop, wrapped in a try command to catch keyboard interrupts. | This is an example of a main program loop, wrapped in a try command to catch keyboard interrupts. | ||
- | Modules required: | + | **Checklist** |
- | * signal (keyboard interrupts) | + | * Modules required: |
+ | |||
+ | ---- | ||
+ | |||
+ | ====== The Code ====== | ||
+ | |||
+ | <code python> | ||
+ | import signal | ||
- | < | ||
def main(): | def main(): | ||
# Main program loop: Until quit is detected, ask user what to do | # Main program loop: Until quit is detected, ask user what to do | ||
Line 26: | Line 35: | ||
#trap keyboard interrupts (control+c), | #trap keyboard interrupts (control+c), | ||
except (KeyboardInterrupt): | except (KeyboardInterrupt): | ||
- | input(" | + | input(" |
continue | continue | ||
# END OF WHILE LOOP | # END OF WHILE LOOP | ||
Line 32: | Line 41: | ||
## End of main() ## | ## End of main() ## | ||
</ | </ | ||
+ | |||
+ | ---- | ||
+ |