pythonjupyter-notebookjupyter-console

Which dunder gets called in jupyter when I run an object alone in a cell


Let's say I have some class_object_instance of some_really_complex_object in my jupyter notebook.

Eg:

In [4]: import some_wild_proprietary_code as some_crazy_import
        class_object_instance = some_crazy_import.some_really_complex_object()

Then I run:

In [5]: class_object_instance

and I get:

Out[5]: <some_wild_proprietary_code.some_really_complex_object at 0x22918d68>

What is actually getting called when I run the cell?

I'd like to try to control the default behavior and have Out[5]: show somethign I could control, but maybe it's a jupyter-level thing and not a class object level thing.


Solution

  • You can control the representation of the object by modifying the __repr__ method.