Python as a Language is Unescabably Coupled with its Implementation Part 2: The Tracer
python
I was recently discussing some dumb PYthon tricks at work with some colleagues and showed them this old Gist I wrote, which in modern times I would rewrite to look like this:
import functools import inspect import sys @functools.lru_cache def getlines(filename): with open(filename, "r") as file_handle: return tuple(file_handle) @functools.lru_cache def getline(filename, line_number): return getlines(filename)[line_number - 1] def tracefunction(frame, event, arg): if event == "line": info = inspect.getframeinfo(frame) fname, lineno, fn = info.
Read more...
Read more...