Skip to content

Instantly share code, notes, and snippets.

@n9986
Created March 14, 2013 13:12
Show Gist options
  • Save n9986/5161185 to your computer and use it in GitHub Desktop.
Save n9986/5161185 to your computer and use it in GitHub Desktop.
Python simple factory style
class MultipleChoice():
name = "multiplechoice"
class QuestionBuilderFactory():
classes = {}
def register(self, cls):
# print getattr(cls, name)
print cls.name
self.classes[cls.name] = cls
def create_class(self, t):
return self.classes[t]()
qb = QuestionBuilderFactory()
qb.register(MultipleChoice)
print qb.create_class("multiplechoice")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment