Skip to content

Instantly share code, notes, and snippets.

@JimDennis
Created July 9, 2014 06:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JimDennis/4992c4901f7152124a54 to your computer and use it in GitHub Desktop.
Save JimDennis/4992c4901f7152124a54 to your computer and use it in GitHub Desktop.
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
@JimDennis
Copy link
Author

Note: might want the var = defaultValue to be var = str(defaultValue) to ensure that you always return strings!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment