There seem to be different ways to return the __repr__ function.
I have an InfoObj class that stores a number of things, some of which I especially do not want users of this class to install themselves. I admit that nothing is protected in python, and they can just dive and install it anyway, but it seems that defining it in __init__ makes it more likely, someone can see it and assume that it just passes it.
(Example: logical elements that are set by the check function when it determines that the object has been completely filled, and values ββthat are calculated from other values ββwhen enough information is stored for this ... for example, A = B + C, therefore after that as A and B are set, C is computed, and the object is marked Valid = True.)
So, considering all this, what is the best way to develop __ repr __ output?
bob = InfoObj(Name="Bob")
... a point like C would not be happy to accept everything that I set 'private' in C ++ as arguments to the constructor, and make teammates using a class configured using interface functions, even if it is more for them. In this case, I would define a constructor that does not accept certain things, and a separate function that is a bit more difficult to notice for __repr__ purposes
If that matters, I plan to store these python objects in the database using their __repr__ output and retrieve them using eval() , at least if I don't come up with a better way. The result of a teammate creating a complete object manually instead of going through the corresponding functions of the interface is that one type of information retrieval can be unstable until someone finds out what he did.
python constructor repr
Brian Jun 15 2018-11-11T00: 00Z
source share