Reputation: 49196
I've always thought that Jupyter simply printed out the repr
of an object, but that is not the case.
Here is an example. If I evaluate this in a notebook:
obj = type(2)
obj
I just get: int
.
If I do instead
print(obj)
I get: <class 'int'>
.
So: what is the Python instruction to simulate what the notebook does during the evaluation of a variable?
Upvotes: 0
Views: 561
Reputation: 51979
Jupyter/IPython uses a rather complex pretty printer. Concerning your example of int
, it has a printer for classes/type.
Basically what it does is it gets the class' name via cls.__qualname__
(py3) or cls.__name__
(py2&3) and the module via cls.__module__
, and prints them as <module.name>
. For builtins, the module name is silently ignored.
Upvotes: 1