Skillversitas

Saving QtConsole Output to HTML

QtConsole sessions produce valuable output - results, plots, error traces - that you often want to keep or share. You can capture the console's history and rich output into an HTML file, the same way notebooks export, turning a console session into a shareable artifact.

Session Logging to File

IPython can log the session to a file as it runs. In the console:

%%log session.log
# every subsequent input and output is appended to session.log
1 + 1
import sys; sys.version

The log captures inputs and plain-text outputs; rich outputs (figures) are described rather than embedded.

History to HTML

IPython can render recent history as HTML directly in the console:

%history -o -g

For a saved file, use the history manager from within the session:

import get_ipython
hm = get_ipython().history_manager
with open("session.html", "w") as f:
    f.write("<pre>" + "\n".join(hm.get_range(1, len(hm.input_hist_parsed) + 1)) + "</pre>")

Capturing Rich Output

For plots and tables, the reliable route is to generate them as files in the session, then assemble an HTML page referencing them:

import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 1, 2])
plt.savefig("out/fig1.png")

html = '''<h1>Session notes</h1>
<p>Figure 1: example</p>
<img src="out/fig1.png">
<pre><code></code></pre>
'''
with open("report.html", "w") as f:
    f.write(html)

Bridge to a Real Notebook

If the console session matters long-term, the cleanest "save" is to convert the work into a notebook: recreate the key cells (history recall makes this fast: %history -g for the important lines) and run nbconvert to HTML or PDF.

Summary

Capture qtconsole output with %%log to a text file, render history with %history -o or the history manager into HTML, and save rich outputs (figures, tables) as files referenced from a small HTML report. For permanent records, port the key cells into a notebook and export with nbconvert.