Guest User

Untitled

a guest
Mar 18th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. def __repr__wrapper(self):
  2. """Show all attributes."""
  3. return "Attributes: "+", ".join(list(self.__dict__.keys()))
  4.  
  5. def __repr__dec(func):
  6. """Replaces the __repr__ function of a class with __repr__wrapper"""
  7. def call(*args, **kwargs):
  8. func.__repr__ = __repr__wrapper
  9. result = func(*args, **kwargs)
  10. return result
  11. return call
  12.  
  13. @__repr__dec
  14. class Container(object):
  15. """Empty class.
  16. """
  17. def __init__(self, *args, **kwargs):
  18. self.metadata = args[0]
  19. for k,v in kwargs.items():
  20. self.__dict__[k] = v
  21.  
  22. occ = Container(42, how="now")
  23.  
  24. if __name__ == "__main__":
  25. print(occ)
  26. print(occ.metadata)
  27. print(occ.how)
Add Comment
Please, Sign In to add comment