In an ipython terminal, suppose I create an object and then just type the object's name and hit return, what attributes/methods of that object (and in what order) are queried to produce the output that is returned to the screen?
E.g.,
In [1]: from mymodule import myclass
In [2]: C = myclass()
In [3]: C # hit return
Out[3]:
What attributes/methods of C are queried to produce the output in Out[3]
?
Update: From the answer (and also a duplicate question that I found, it shows that __repr__
is called. However, I have a class that defines __repr__
, but it doesn't appear to be being used and I get the following traceback error:
/usr/local/lib/python2.7/dist-packages/IPython/core/displayhook.pyc in __call__(self, result)
244 self.start_displayhook()
245 self.write_output_prompt()
--> 246 format_dict, md_dict = self.compute_format_data(result)
247 self.update_user_ns(result)
248 self.fill_exec_result(result)
/usr/local/lib/python2.7/dist-packages/IPython/core/displayhook.pyc in compute_format_data(self, result)
148
149 """
--> 150 return self.shell.display_formatter.format(result)
151
152 # This can be set to True by the write_output_prompt method in a subclass
/usr/local/lib/python2.7/dist-packages/IPython/core/formatters.pyc in format(self, obj, include, exclude)
150 return {}, {}
151
--> 152 format_dict, md_dict = self.mimebundle_formatter(obj, include=include, exclude=exclude)
153
154 if format_dict or md_dict:
<decorator-gen-12> in __call__(self, obj, include, exclude)
/usr/local/lib/python2.7/dist-packages/IPython/core/formatters.pyc in catch_format_error(method, self, *args, **kwargs)
215 """show traceback on failed format call"""
216 try:
--> 217 r = method(self, *args, **kwargs)
218 except NotImplementedError:
219 # don't warn on NotImplementedErrors
/usr/local/lib/python2.7/dist-packages/IPython/core/formatters.pyc in __call__(self, obj, include, exclude)
962 return printer(obj)
963 # Finally look for special method names
--> 964 method = get_real_method(obj, self.print_method)
965
966 if method is not None:
/usr/local/lib/python2.7/dist-packages/IPython/utils/dir2.pyc in get_real_method(obj, name)
63
64 try:
---> 65 canary = getattr(obj, '_ipython_canary_method_should_not_exist_', None)
66 except Exception:
67 return None
where eventually it tries to use the __getattr__
method! In my class I have my own defined __getattr__
method, could this be causing a problem?