Created
March 8, 2014 17:47
-
-
Save curzona/9435778 to your computer and use it in GitHub Desktop.
Prompt the user for a value.
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
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