__FILE__ and __LINE__ in Python

Ned Batchelder shows how to use sys._getframe() to get the current (or calling) filename, line, and function in Python. In C, this happens at compile-time. Practically everything in Python happens at runtime, so this is slower, but you can also do things like inspect the local variables in the stack frames.