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 6373123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:19:29+00:00 2026-05-25T01:19:29+00:00

Assuming I have two Python modules and path_b is in the import path: #

  • 0

Assuming I have two Python modules and path_b is in the import path:

# file: path_b/my_module.py
print "I was imported from ???"

#file: path_a/app.py
import my_module

Is it possible to see where the module is imported from? I want an output like “I was imported from path_a/app.py”, if I start app.py (because I need the file name).

Edit:
For better understanding; I could write:

# file: path_b/my_module.py
def foo(file):
    print "I was imported from %s" % file

#file: path_a/app.py
import my_module
my_module.foo(__file__)

So the output would be:

$> python path_app.py
I was imported from path_a/app.py
  • 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-25T01:19:30+00:00Added an answer on May 25, 2026 at 1:19 am

    There may be an easier way to do this, but this works:

    import inspect
    
    print(inspect.getframeinfo(inspect.getouterframes(inspect.currentframe())[1][0])[0])
    

    Note that the path will be printed relative to the current working directory if it’s a parent directory of the script location.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two related Python 'import' questions. They are easily testable, but I want
Assuming you have two developers working on a project locally on their laptops (A
Assuming you have two lists defined in an xml schema, call them A and
Let's say I have two tables: Report Comment And assuming I have a database
Assuming I have the following two JQuery functions - The first, which works: $(#myLink_931).click(function
Assuming I have two SQL tables consisting of a single column, i.e. Table 1
I have two distinct modules that can be used independently, but Module2 is dependent
I have two tables: regions <id> points <region_id, x, y> Assuming there are exactly
I have two lists in Python: temp1 = ['One', 'Two', 'Three', 'Four'] temp2 =
This I'm assuming is a relatively trivial problem. I have two connected sortable lists,

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.