Skip to main content
A Jupyter cell can produce more than one output. When you call plt.show() or display(), or when the last line of a cell evaluates to a value, the kernel emits an output message. Each of those messages becomes a Result object inside execution.results. The Result holds all the MIME representations that the kernel provided for that output.

The Result object

execution.results is a list[Result]. Each Result exposes known MIME types as named fields: Fields that are not present in the kernel output are None. Check a field before using it.

Checking available formats

Call result.formats() to get a list of the field names that are populated for a given result.

The main result flag

Each Result has an is_main_result boolean. It is True for the execute_result message — the value of the last expression in the cell. It is False for display_data messages produced by plt.show(), display(), and similar calls. The execution.text convenience property returns the text field of the main result.

Matplotlib example

Iterating and decoding outputs

png and jpeg fields are base64-encoded strings, exactly as the Jupyter kernel delivers them. Decode with base64.b64decode(r.png) to get raw bytes you can write to a file or pass to an image library.
String expression values have their surrounding quotes stripped automatically. If a cell evaluates to 'hello', result.text is hello, not 'hello'.