Created
September 14, 2017 08:49
-
-
Save WorryingWonton/7220bb556739185311200fd0b114705c to your computer and use it in GitHub Desktop.
Answer to Steve's gist.
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
class QuestionA: | |
def __init__(self, question_dict): | |
self.question_dict = question_dict | |
class QuestionB: | |
def __init__(self, question_text, answer_dict): | |
self.question_text = question_text | |
self.answer_dict = answer_dict | |
qa = QuestionA({'What is a question?':'You just asked one.'}) | |
qb = QuestionB('What is a question?', {'You just asked one.': True}) | |
qa_text = [key for key in qa.question_dict.keys()] | |
# for key, value in qa_text.items(): | |
# print(key) | |
print(qa_text[0]) | |
qb_text = qb.question_text | |
print(qb_text) |
Author
WorryingWonton
commented
Sep 14, 2017
•
import json
class ObjectEncoder(json.JSONEncoder):
def default(self, obj):
return obj.__dict__
quiz = Quiz('My first quiz', 'basics', 1, [Question("What is the name of this quiz?", {"my first quiz": True})])
print(json.dumps(quiz, cls=ObjectEncoder))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment