Skip to content

Commit

Permalink
Python implementation for psource (aimacode#613) (aimacode#619)
Browse files Browse the repository at this point in the history
* Added python code for psource (aimacode#613)

* added psource code with optional highlighting (aimacode#613)
  • Loading branch information
VishnuDuttSharma authored and norvig committed Aug 15, 2017
1 parent b47888c commit a58fe90
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions notebook.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down

0 comments on commit a58fe90

Please sign in to comment.