Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
bringing it all together in notebook
  • Loading branch information
antmarakis authored Aug 15, 2017
commit b51593f43428d52488dbeb661a356b3da7a42715
25 changes: 18 additions & 7 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 @@ -15,14 +17,8 @@
#______________________________________________________________________________


def psource(*functions):
"""Print the source code for the given function(s)."""
import inspect

print('\n\n'.join(inspect.getsource(fn) for fn in functions))


def pseudocode(algorithm):
"""Print the pseudocode for the given algorithm."""
from urllib.request import urlopen
from IPython.display import Markdown

Expand All @@ -33,6 +29,21 @@ def pseudocode(algorithm):
md = '#' + md
return Markdown(md)


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)


# ______________________________________________________________________________


Expand Down