Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
Copy link

JimDennis commented Jul 9, 2014

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