printing line numbers for debugging purpose
Mark McEahern
marklists at mceahern.com
Sat Jan 8 18:11:57 EST 2005
Philippe C. Martin wrote:
>Hi,
>
>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__':
try:
main()
except:
import sys, traceback
t, v, tb = sys.exc_info()
traceback.print_tb(tb)
More information about the Python-list
mailing list