VikkaLorel

debug str and repr

May 11th, 2022
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. class Foobar:
  2.     def __str__(self):
  3.         return f'{self.__class__.__name__}: ({", ".join((str(v) for v in self.__dict__.values()))})'
  4.  
  5.     def __repr__(self):
  6.         return f'<{self.__class__.__name__}: {self.__dict__}>'
  7.  
  8.     def __init__(self):
  9.         self.foo = 'foo_value'
  10.         self.bar = 'bar_value'
  11.         self.baz = 'baz_value'
  12.  
  13.  
  14. f = Foobar()
  15. print(f)
  16. print(str(f))  # == print(f)
  17. print(repr(f))
  18.  
Add Comment
Please, Sign In to add comment