Created
July 9, 2011 15:07
-
-
Save KyeRussell/1073643 to your computer and use it in GitHub Desktop.
Prompt Method
This file contains hidden or 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
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