Framework for asking questions
Project description
Question Framework helps you to ask questions and get answers in a declarative way!
Question Framework
Basic Usage
from question_framework.question import Question, RepeatedQuestion, BranchedQuestion
from question_framework.user_input import ask
questions = [Question("Name", "Your name:")]
answers = ask(questions)
print(answers)
Output:
Your name:
foobar
{'Name': 'foobar'}
Question Types
Question
Question
is basically a question with an answer.
questions = [Question("Name", "Your name:")]
answers = ask(questions)
print(answers)
Output:
Your name:
John Doe
{'Name': 'John Doe'}
Repeated Question
RepeatedQuestion
can be used to ask same question consecutively.
questions = [RepeatedQuestion("Password", "Your password:", 2)]
answers = ask(questions)
print(answers)
Output:
Your password:
123
Your password:
321
Your password:
765
{'Password': ['123', '321', '765']}
Branched Question
BranchedQuestion
can be used to create one way adventures.
game = [BranchedQuestion("Main", "Where to go? [N | E | S | W]", [
Question("N", "North is cold. You died! (type anything to exit)"),
Question("E", "You trigerred the trap. (type anything to exit)"),
BranchedQuestion("S", "You found a tresure chest! [open | leave]", [
Question("open", "It was a trap! (type anything to exit)"),
Question("leave", "You leave the cave.. (type anything to exit)"),
]),
Question("W", "West is wild, you died! (type anything to exit)"),
])]
answers = ask(game)
Validations
A validation function can be specified to validate answers. If validation fails, user will be asked to enter the input again.
Question("Password", "Enter password:", validation=lambda x: len(x) > 5)
Post process
A post process can be specified to transform answer.
Question("Firstname", "Enter firstname:", post_process=lambda x: x.upper())
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for question_framework-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55a69ada8d5c09c1050d5fac9fa9a411776130992c5a67c85aadcbe2e8823889 |
|
MD5 | 9b87b9251dcfa7eb2b2d8f5a1bd34f51 |
|
BLAKE2b-256 | 47cef904ecf5a6231d42b96f970540103b91ceaa4b10572ad937f0a395f20a73 |