Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1091041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:27:47+00:00 2026-05-16T23:27:47+00:00

Python 2.5 to 2.7: #a.py: def foo(): pass #b.py from a import foo foo()

  • 0

Python 2.5 to 2.7:

#a.py:
def foo():
    pass

#b.py
from a import foo
foo()

From foo(), I’d like to know that it has benn called in the “b” module. The only way I can think of right now is raising an exception, catching it and inspecting the traceback (going one level up). Is there a mare natural way of doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:27:47+00:00Added an answer on May 16, 2026 at 11:27 pm

    You can do this with the inspect module.

    E.g.

    #!/usr/bin/env python
    # a.py
    import inspect
    
    def foo():
        for item in inspect.stack():
            print item
    

    –

    #!/usr/bin/env python
    # b.py
    
    from a import foo
    
    foo()
    

    –

    $ python b.py
    (<frame object at 0x2026fb0>, '/home/tdb/a.py', 6, 'foo', ['    for item in inspect.stack():\n'], 0)
    (<frame object at 0x1fe4a30>, 'b.py', 5, '<module>', ['foo()\n'], 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a function in Python like so: def foo(x): pass According
I'm new to Python. I have a method that begins: def foo(self, list): length
This Python: data = {} def f(): pass import sys help(sys.modules[__name__]) Prints this: Help
I'm writing a simple xmlrpc programe in python. something like the following: def foo(data):
Consider the following Python (3.x) code: class Foo(object): def bar(self): pass foo = Foo()
Give follow python function define: def Foo(a=0.1, b=1.6): pass when I call 'help(Foo)' ,
It seems that the unittest module has been changed a lot in Python 2.7
Consider the following Python code: def f(*args): for a in args: pass foo =
I'm pretty new at python and I was wondering if this: def func(self, foo):
The python implementation import sys def move(src, dst, tmp, num): if num == 1:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.