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

  • Home
  • SEARCH
  • 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 137309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:05:09+00:00 2026-05-11T07:05:09+00:00

I would like to be able to dynamically retrieve the current executing module or

  • 0

I would like to be able to dynamically retrieve the current executing module or class name from within an imported module. Here is some code:

foo.py:

def f():     print __name__ 

bar.py:

from foo import f  def b(): f() 

This obviously does not work as __name__ is the name of the module that contains the function. What I would like to be access inside the foo module is the name of the current executing module that is using foo. So in the case above it would be bar but if any other module imported foo I would like foo to dynamically have access to the name of that module.

Edit: The inspect module looks quite promising but it is not exactly what I was looking for. What I was hoping for was some sort of global or environment-level variable that I could access that would contain the name of the current executing module. Not that I am unwilling to traverse the stack to find that information – I just thought that Python may have exposed that data already.

Edit: Here is how I am trying to use this. I have two different Django applications that both need to log errors to file. Lets say that they are called ‘AppOne’ and ‘AppTwo’. I also have a place to which I would like to log these files: ‘/home/hare/app_logs‘. In each application at any given point I would like to be able to import my logger module and call the log function which writes the log string to file. However what I would like to do is create a directory under app_logs that is the name of the current application (‘AppOne’ or ‘AppTwo’) so that each application’s log files will go in their respective logging directories.

In order to do this I thought that the best way would be for the logger module to have access to some sort of global variable that denotes the current application’s name as it is responsible for knowing the location of the parent logging directory and creating the application’s logging directory if it does not yet exist.

  • 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. 2026-05-11T07:05:09+00:00Added an answer on May 11, 2026 at 7:05 am

    From the comment — not the question.

    I am simply curious to see if what I am trying to do is possible.

    The answer to "is it possible" is always "yes". Always. Unless your question involves time travel, anti-gravity or perpetual motion.

    Since the answer is always "yes", your question is ill-formed. The real question is "what’s a good way to have my logging module know the name of the client?" or something like that.

    The answer is "Accept it as a parameter." Don’t mess around with inspecting or looking for mysterious globals or other tricks.

    Just follow the design pattern of logging.getLogger() and use explicitly-named loggers. A common idiom is the following

    logger= logging.getLogger( __name__ ) 

    That handles almost all log naming perfectly.

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

Sidebar

Ask A Question

Stats

  • Questions 79k
  • Answers 79k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This one does it for me: (?<!\.[0-9a-z]*)[0-9] This does a… May 11, 2026 at 4:12 pm
  • Editorial Team
    Editorial Team added an answer Yes. See here. (?s:) Should turn on single line mode. May 11, 2026 at 4:12 pm
  • Editorial Team
    Editorial Team added an answer you can setup a forward in the index.jsp at the… May 11, 2026 at 4:12 pm

Related Questions

I am writing a addressbook module for my software right now. I have the
I know I can do something like the following code to dynamically create a
What is the best way to read and/or set Internet Explorer options from a
As the question states, I would mainly like to know whether or not my

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.