Source line number for log purpose (newbie)
T. C. Mits
71351.356 at compuserve.com
Sat Sep 25 14:58:45 EDT 1999
Thanks for the feedback and the code, S. Brentrup. I like the traceback
method better than the throwing of an exception; it seems "more correct,
right on target, so direct."
Anyway, I'll RT.M regarding both libraries.
Thanks.
Siggy Brentrup <bsb at baal.infodrom.north.de> wrote in message
news:873dw3rkse.fsf at baal.winnegan.fake...
> --Multipart_Sat_Sep_25_18:57:37_1999-1
> Content-Type: text/plain; charset=US-ASCII
>
>
> It's easy, feel free to use the attached code (quoted-printable to get
> tabs right)
>
> CU
> Siggy
>
> #! /usr/bin/env python
>
> import sys, traceback
>
> def logger(message):
> file, line, func, txt =3D traceback.extract_stack(None, 2)[0]
> print '%(file)s:%(line)s: in function %(func)s - %(message)s' \
> % locals()
>
> def main():
> logger( 'Hi there!' )
> logger( 'and again' )
>
> if __name__ =3D=3D '__main__':
> main()
> logger('Bye')
More information about the Python-list
mailing list