Created
July 9, 2014 06:00
-
-
Save JimDennis/4992c4901f7152124a54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def easy_input (prompt, defaultValue=None): | |
'''Doc string: idiomatically read input with optional default value: | |
''' | |
prompt = '%s%s: ' % (prompt, ('[%s]' % defaultValue) if defaultValue is not None else '') | |
var = raw_input(prompt) | |
if not var: | |
var = defaultValue | |
return var |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: might want the var = defaultValue to be var = str(defaultValue) to ensure that you always return strings!