In IPython, typing the name of a class and hitting Enter displays the class's fully-qualified name. How do I programmatically access this name as a string? It's not the same as what str()
and repr()
return, and because this is a class, not an instance of that class, defining its magic methods __str__
and/or __repr__
wouldn't help.
Already been to this answer, but it's about the default Python interpreter, not IPython.
In [1]: class MyClass:
...: pass
...:
In [2]: MyClass
Out[2]: __main__.MyClass
In [3]: str(MyClass)
Out[3]: "<class '__main__.MyClass'>"
In [4]: repr(MyClass)
Out[4]: "<class '__main__.MyClass'>"
What method should I call on MyClass
so I can get the same output when pressing enter on a class object?, __main__.MyClass
, as a string?
As someone suggested this answer which I was already aware, but I am asking the question here is more curious about what internal method was called when hitting "enter" on a class object.