Assume I have a class that inherits from object. I create an instance of it pass that to print. It will display something like <__main__.ObjName object at 0xxxxxx>
. Is there an object method that can be overridden to provide a return value when the object is accessed this way?
Asked
Active
Viewed 50 times
0
-
if you don't define str then the output is using repr – Padraic Cunningham Jun 09 '15 at 00:39
2 Answers
4
-
This was exactly what I was looking for. Thanks! Any key pitfalls using one of these vs the other? – Lother Jun 09 '15 at 00:40
-
1@Lother have a look at [this question](http://stackoverflow.com/questions/1436703/difference-between-str-and-repr-in-python) for a comparison. – George Brighton Jun 09 '15 at 00:41