Syntax highlighting

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis præsentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occæcati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.

Let’s see if syntax highlighting works:

 1 def src(obj):
 2     """Read the source of an object in the interpreter."""
 3     def highlight(source):
 4         try:
 5             import pygments
 6             from pygments.lexers import get_lexer_by_name
 7             from pygments.formatters.terminal import TerminalFormatter
 8         except ImportError:
 9             return source
10         return pygments.highlight(
11             source,
12             get_lexer_by_name('python'),
13             TerminalFormatter()
14         )
15     import inspect
16     import subprocess
17     source = inspect.getsource(obj)
18     pager = subprocess.Popen(('less', '-R'), stdin=subprocess.PIPE)
19     pager.communicate(highlight(source).encode('utf-8'))
20     pager.wait()

😋