Show More
@@ -5,7 +5,7 b' General purpose utilities.' | |||
|
5 | 5 | This is a grab-bag of stuff I find useful in most programs I write. Some of |
|
6 | 6 | these things are also convenient when working at the command line. |
|
7 | 7 | |
|
8 |
$Id: genutils.py 13 |
|
|
8 | $Id: genutils.py 1349 2006-06-04 00:57:43Z fperez $""" | |
|
9 | 9 | |
|
10 | 10 | #***************************************************************************** |
|
11 | 11 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> |
@@ -992,28 +992,27 b' def ask_yes_no(prompt,default=None):' | |||
|
992 | 992 | |
|
993 | 993 | If default is given (one of 'y','n'), it is used if the user input is |
|
994 | 994 | empty. Otherwise the question is repeated until an answer is given. |
|
995 | If EOF occurs 20 times consecutively, the default answer is assumed, | |
|
996 | or if there is no default, an exception is raised to prevent infinite | |
|
997 | loops. | |
|
995 | ||
|
996 | An EOF is treated as the default answer. If there is no default, an | |
|
997 | exception is raised to prevent infinite loops. | |
|
998 | 998 | |
|
999 | 999 | Valid answers are: y/yes/n/no (match is not case sensitive).""" |
|
1000 | 1000 | |
|
1001 | 1001 | answers = {'y':True,'n':False,'yes':True,'no':False} |
|
1002 | 1002 | ans = None |
|
1003 | eofs, max_eofs = 0, 20 | |
|
1004 | 1003 | while ans not in answers.keys(): |
|
1005 | 1004 | try: |
|
1006 | 1005 | ans = raw_input(prompt+' ').lower() |
|
1007 | 1006 | if not ans: # response was an empty string |
|
1008 | 1007 | ans = default |
|
1009 | eofs = 0 | |
|
1010 | except (EOFError,KeyboardInterrupt): | |
|
1011 | eofs = eofs + 1 | |
|
1012 | if eofs >= max_eofs: | |
|
1013 |
|
|
|
1014 |
|
|
|
1015 |
|
|
|
1016 |
|
|
|
1008 | except KeyboardInterrupt: | |
|
1009 | pass | |
|
1010 | except EOFError: | |
|
1011 | if default in answers.keys(): | |
|
1012 | ans = default | |
|
1013 | ||
|
1014 | else: | |
|
1015 | raise | |
|
1017 | 1016 | |
|
1018 | 1017 | return answers[ans] |
|
1019 | 1018 |
@@ -1,5 +1,8 b'' | |||
|
1 | 1 | 2006-06-03 Fernando Perez <Fernando.Perez@colorado.edu> |
|
2 | 2 | |
|
3 | * IPython/genutils.py (ask_yes_no): treat EOF as a default answer | |
|
4 | instead of looping 20 times. | |
|
5 | ||
|
3 | 6 | * IPython/ipmaker.py (make_IPython): honor -ipythondir flag |
|
4 | 7 | correctly at initialization time. Bug reported by Krishna Mohan |
|
5 | 8 | Gundu <gkmohan-AT-gmail.com> on the user list. |
General Comments 0
You need to be logged in to leave comments.
Login now