functions

Discussion in 'Python' started by Girish, Nov 28, 2008.

  1. Girish

    Girish Guest

    Hello,

    Is ter any way to identify the file name and the path in which the
    function is called.

    for example: if the function definition is in the file c:\script1.py
    and if I call this function in a script: c:\script2.py than in the
    function definition part(script1.py) some how I need to know that its
    called in c:\script2.py.

    Thanks,
    Giri
     
    Girish, Nov 28, 2008
    #1
    1. Advertising

  2. Girish

    Peter Otten Guest

    Girish wrote:

    > Is ter any way to identify the file name and the path in which the
    > function is called.
    >
    > for example: if the function definition is in the file c:\script1.py
    > and if I call this function in a script: c:\script2.py than in the
    > function definition part(script1.py) some how I need to know that its
    > called in c:\script2.py.


    You can inspect the stack:

    import sys
    import inspect

    def some_func():
    print inspect.getfile(sys._getframe(1))

    Peter
     
    Peter Otten, Nov 28, 2008
    #2
    1. Advertising

  3. Girish

    Girish Guest

    On Nov 28, 1:46 pm, Peter Otten <> wrote:
    > Girish wrote:
    > > Is ter any way to identify the file name and the path in which the
    > > function is called.

    >
    > > for example: if the function definition is in the file c:\script1.py
    > > and if I call this function in a script: c:\script2.py than in the
    > > function definition part(script1.py) some how I need to know that its
    > > called in c:\script2.py.

    >
    > You can inspect the stack:
    >
    > import sys
    > import inspect
    >
    > def some_func():
    >     print inspect.getfile(sys._getframe(1))
    >
    > Peter


    Thanks a lot Peter.
     
    Girish, Nov 28, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad
    Replies:
    11
    Views:
    841
    tshad
    May 27, 2005
  2. Timothy Wong
    Replies:
    3
    Views:
    429
    Timothy Wong
    May 20, 2004
  3. ILLOGIC
    Replies:
    1
    Views:
    379
    Rob Williscroft
    Jun 1, 2004
  4. Xiangliang Meng
    Replies:
    1
    Views:
    1,652
    Victor Bazarov
    Jun 21, 2004
  5. Steven T. Hatton

    Passing member functions to C functions?

    Steven T. Hatton, Oct 4, 2004, in forum: C++
    Replies:
    7
    Views:
    1,329
    David Hilsee
    Oct 7, 2004
Loading...

Share This Page