Skip to content

Instantly share code, notes, and snippets.

@curzona
Created March 8, 2014 17:47
Show Gist options
  • Save curzona/9435778 to your computer and use it in GitHub Desktop.
Save curzona/9435778 to your computer and use it in GitHub Desktop.
Prompt the user for a value.
import sys
import types
castor = {types.IntType:int, types.LongType:long, types.FloatType:float, types.BooleanType:bool}
def ask(message, default):
sys.stdout.write(message + " [" + str(default) + "]:")
input = sys.stdin.readline().strip()
if input == "":
return default
elif type(default) in castor:
return castor[type(default)](input)
else:
return input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment