- #1
m4r35n357
- 658
- 148
[TLDR] what terrible things will happen if I don't?
I've been searching this for a while and all I have found are various "explanations" that __repr__() should provide an "official" representation of the object (or is it class, or instance?). Also it should be usable as input to eval() - (to construct an instance I suppose . . . ?). The documentation I have seen on the matter assumes that the user already knows what it is for ;)
Anyhow, I have not yet encountered a situation that causes me to believe that I need to define it. Perhaps the use case just doesn't apply to what I am doing (number crunching).
Here, jet is a list of floats, diff is a bool, and n in an int. So, is __repr__() supposed to make a string "constructor call" for eval? If so, how should I proceed?
I've been searching this for a while and all I have found are various "explanations" that __repr__() should provide an "official" representation of the object (or is it class, or instance?). Also it should be usable as input to eval() - (to construct an instance I suppose . . . ?). The documentation I have seen on the matter assumes that the user already knows what it is for ;)
Anyhow, I have not yet encountered a situation that causes me to believe that I need to define it. Perhaps the use case just doesn't apply to what I am doing (number crunching).
Python:
class Series:
def __init__(self, jet, diff=False):
self.jet = jet
self.n = len(self.jet)
if diff:
self.jet[1] = D1
self.diff_status = diff