MCPcopy Index your code
hub / github.com/ipython/ipython / ask_yes_no

Function ask_yes_no

IPython/utils/io.py:84–115  ·  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

82 return False
83
84def ask_yes_no(prompt, default=None, interrupt=None):
85 """Asks a question and returns a boolean (y/n) answer.
86
87 If default is given (one of 'y','n'), it is used if the user input is
88 empty. If interrupt is given (one of 'y','n'), it is used if the user
89 presses Ctrl-C. Otherwise the question is repeated until an answer is
90 given.
91
92 An EOF is treated as the default answer. If there is no default, an
93 exception is raised to prevent infinite loops.
94
95 Valid answers are: y/yes/n/no (match is not case sensitive)."""
96
97 answers = {'y':True,'n':False,'yes':True,'no':False}
98 ans = None
99 while ans not in answers.keys():
100 try:
101 ans = input(prompt+' ').lower()
102 if not ans: # response was an empty string
103 ans = default
104 except KeyboardInterrupt:
105 if interrupt:
106 ans = interrupt
107 print("\r")
108 except EOFError:
109 if default in answers.keys():
110 ans = default
111 print()
112 else:
113 raise
114
115 return answers[ans]
116
117
118def temp_pyfile(src: str, ext: str='.py') -> str:

Callers 3

kill_embeddedMethod · 0.90
ask_yes_noMethod · 0.90
startMethod · 0.85

Calls 2

inputFunction · 0.85
keysMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…