get line number and filename in a source file

Dave Angel davea at
Wed Nov 25 07:58:56 CET 2009

Peng Yu wrote:
> __LINE__ __FILE__ in C++ can give the current line number and
> filename. Is there a similar thing in python that can give me the
> current line number and filename?
> Is there a similar thing to __PRETTY_FUNCTION__ (also from C++)?
mod.__name__  gives the module name, and   mod.__file__  gives the full 
path to the given module.  Or if you need those for the current module, 
just leave off the prefix.

For line number information, you probably can get it from the inspect 
module, but I don't have any direct experience.  I do have the following 
untested line
in my notes:


More information about the Python-list mailing list