Skip to content

Instantly share code, notes, and snippets.

@caffeine-potent
Created February 23, 2017 19:12
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 caffeine-potent/0eebfaa7ffbb823fb15bbff6715cd34a to your computer and use it in GitHub Desktop.
Save caffeine-potent/0eebfaa7ffbb823fb15bbff6715cd34a to your computer and use it in GitHub Desktop.
Extending Dict to Ask for user input.
class info(dict):
def add_item(self, item_name, question, type = None):
answer = raw_input(question)
if type is not None:
answer = type(answer)
self[item_name] = answer
a = info()
a.add_item("name", "What is your name? ")
a.add_item("quest", "What is your quest? ")
a.add_item("wsv", "What is the air speed velocity of an uladen swallow? ")
print(a)
print(a["name"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment