On this page
article
Readable repr
Implement repr for debugging.
Category: oop
Problem
Implement repr for debugging.
Solution
def __repr__(self):
return f'User(name={self.name!r})'
Notes
- Adapt variable names and paths to your project
- Add error handling for production use
- See related chapters in the Learning Path