Interactively choose one of the items.
(items, title_text, question_text)
| 108 | |
| 109 | |
| 110 | def choose(items, title_text, question_text): |
| 111 | """ |
| 112 | Interactively choose one of the items. |
| 113 | """ |
| 114 | print(title_text) |
| 115 | |
| 116 | for i, item in enumerate(items, start=1): |
| 117 | print('%d) %s' % (i, item)) |
| 118 | print('%d) Abort' % (i + 1)) |
| 119 | |
| 120 | selected = input(question_text) |
| 121 | try: |
| 122 | index = int(selected) |
| 123 | except ValueError: |
| 124 | index = -1 |
| 125 | if not (index - 1) in range(len(items)): |
| 126 | print('Aborting.') |
| 127 | return None |
| 128 | |
| 129 | return items[index - 1] |
| 130 | |
| 131 | |
| 132 | def scan(): |
no outgoing calls
no test coverage detected