filename of calling function?

Phlip phlip2005 at gmail.com
Sat Nov 28 17:40:41 CET 2009


On Nov 28, 8:19 am, Phlip <phlip2... at gmail.com> wrote:
> Consider these two python modules:
>
> aa.py
>
> def a():
>     print '?'
>
> bb.py
>   import aa
>
> def bb():
>   aa.a()
>
> bb()
>
> How do I make the print line emit the filename of bb.py? (It could be
> anything.)

        try:
            raise None
        except:
            import sys
            from traceback import extract_tb, extract_stack
            frame = sys.exc_info()[2].tb_frame.f_back
            calling_file = extract_stack(frame, 2)[1][0]



More information about the Python-list mailing list