def a():
print __name__
Is there any chance I can have such a function, but have it print the “correct” module name if imported by another module and called from there?
“Correct” module name should always be the one it is called from.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
The sys module provides a CPython specific way to lookup your caller:
The _getframe() function is documented here, and frame objects are documented here.