MCPcopy Create free account
hub / github.com/ipython/ipython / ask_yes_no

Function ask_yes_no

IPython/utils/io.py:157–188  ·  view source on GitHub ↗

Asks a question and returns a boolean (y/n) answer. If default is given (one of 'y','n'), it is used if the user input is empty. If interrupt is given (one of 'y','n'), it is used if the user presses Ctrl-C. Otherwise the question is repeated until an answer is given. An EOF is

(prompt, default=None, interrupt=None)

Source from the content-addressed store, hash-verified

155
156
157def ask_yes_no(prompt, default=None, interrupt=None):
158 """Asks a question and returns a boolean (y/n) answer.
159
160 If default is given (one of 'y','n'), it is used if the user input is
161 empty. If interrupt is given (one of 'y','n'), it is used if the user
162 presses Ctrl-C. Otherwise the question is repeated until an answer is
163 given.
164
165 An EOF is treated as the default answer. If there is no default, an
166 exception is raised to prevent infinite loops.
167
168 Valid answers are: y/yes/n/no (match is not case sensitive)."""
169
170 answers = {'y':True,'n':False,'yes':True,'no':False}
171 ans = None
172 while ans not in answers.keys():
173 try:
174 ans = input(prompt+' ').lower()
175 if not ans: # response was an empty string
176 ans = default
177 except KeyboardInterrupt:
178 if interrupt:
179 ans = interrupt
180 print("\r")
181 except EOFError:
182 if default in answers.keys():
183 ans = default
184 print()
185 else:
186 raise
187
188 return answers[ans]
189
190
191def temp_pyfile(src, ext='.py'):

Callers 3

kill_embeddedMethod · 0.90
ask_yes_noMethod · 0.90
startMethod · 0.85

Calls 1

inputFunction · 0.85

Tested by

no test coverage detected