Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 24th, 2012  |  syntax: None  |  size: 0.55 KB  |  views: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class_register = {}
  2.  
  3. class Foo(object):
  4.     def __init__(self, **kwargs):
  5.         class_register[self.__class__.__name__] = ??  # what to store here?
  6.         self.__dict__.update(kwargs)
  7.  
  8. new_instance = class_register[result['class_name']](**result['data'])
  9.        
  10. class_register[self.__class__.__name__] = self.__class__
  11.        
  12. def register(cls):
  13.     class_register[cls.__name__] = cls
  14.  
  15. class Foo(object):
  16.     # blah blah
  17.  
  18. register(Foo)
  19.        
  20. def register(cls):
  21.     class_register[cls.__name__] = cls
  22.     return cls
  23.  
  24. @register
  25. class Foo(object):
  26.     # blah blah
clone this paste RAW Paste Data