from IPython.display import HTML, display from inspect import getsource 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)