Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement __repr__ for custom classes #41

Open
carterbox opened this issue Feb 14, 2017 · 3 comments
Open

Implement __repr__ for custom classes #41

carterbox opened this issue Feb 14, 2017 · 3 comments
Assignees
Labels
enhancement A new feature, an improvement, or other addition.
Milestone

Comments

@carterbox
Copy link
Contributor

carterbox commented Feb 14, 2017

Recently I discovered the __repr__ function in python. It seems that it would be useful implement this function such that objects can be recreated from log outputs.

http://stackoverflow.com/a/19597196

@slivingston slivingston added the enhancement A new feature, an improvement, or other addition. label Feb 15, 2017
@slivingston
Copy link
Member

more motivation: entering a variable name at the IPython prompt causes its __repr__ function to be called.

@slivingston
Copy link
Member

Creating __repr__ for the class Polytope might be difficult if you want to include the memoized value of the bounding box because it (the attribute bbox) cannot be assigned by calling __init__.

@johnyf
Copy link
Member

johnyf commented Feb 17, 2017

Following the previous comment and to simplify __repr__, I suggest omitting all attributes that are computed automatically from other values. These comprise dependent information (for the sake of the argument only, we could imagine recomputing them with better precision on a future machine).

__repr__ is a useful mechanism, though I rarely use it. So, it would probably be good to implement this magic method only if someone uses it somewhere. The use case that seems more interesting is data persistence.

Relevant issues:
tulip-control/tulip-control#59
tulip-control/tulip-control#69

@johnyf johnyf self-assigned this Jun 8, 2021
@johnyf johnyf added this to the 0.2.4 milestone Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature, an improvement, or other addition.
Projects
None yet
Development

No branches or pull requests

3 participants