printing line numbers for debugging purpose

Mark McEahern marklists at
Sat Jan 8 18:11:57 EST 2005

Philippe C. Martin wrote:

>All of the methods from my program return None on error (i.e; I do not
>want to assert and have the program exit).
>Is it possible to print the current source file name/line number ?
>ex: in C/C++ I would use the macros __FILE__ and __LINE__.
Consider something like this:
#!/usr/bin/env python

def main():
    raise RuntimeError('whatever')

if __name__ == '__main__':
        import sys, traceback
        t, v, tb = sys.exc_info()

More information about the Python-list mailing list