diff --git a/notebook.py b/notebook.py index 2df7b7721..fc5c4b0f1 100644 --- a/notebook.py +++ b/notebook.py @@ -1,3 +1,5 @@ +from inspect import getsource + from utils import argmax, argmin from games import TicTacToe, alphabeta_player, random_player, Fig52Extended, infinity from logic import parse_definite_clause, standardize_variables, unify, subst @@ -24,6 +26,23 @@ def psource(*functions): # ______________________________________________________________________________ +def psource(*functions): + "Print the source code for the given function(s)." + source_code = '\n\n'.join(getsource(fn) for fn in functions) + try: + from pygments.formatters import HtmlFormatter + from pygments.lexers import PythonLexer + from pygments import highlight + + display(HTML(highlight(source_code, PythonLexer(), HtmlFormatter(full=True)))) + + except ImportError: + print(source_code) + + +# ______________________________________________________________________________ + + def show_iris(i=0, j=1, k=2): """Plots the iris dataset in a 3D plot. The three axes are given by i, j and k,