Skip to content

Instantly share code, notes, and snippets.

@KyeRussell
Created July 9, 2011 15:07
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 KyeRussell/1073643 to your computer and use it in GitHub Desktop.
Save KyeRussell/1073643 to your computer and use it in GitHub Desktop.
Prompt Method
def prompt(message, password=False):
"""
Prompt the user for information.
message - what you're prompting the user for.
password - whether you want a password (invokes getpass instead of vanilla raw_input()).
returns the text returned by the user.
"""
# We don't want a password.
if password == False:
# Print the prompt
print "[\033[33m?\033[0m] " + message.__str__(), end=None
# Grab the input
reply = raw_input()
# Return it
return reply
else:
# We want a password.
try:
passwd = getpass.getpass("[\033[33m?\033[0m] " + message + " ")
except getpass.GetPassWarning:
print("Your password may be shown in clear text. Make sure that nobody is behind you!")
return passwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment