Is it possible to return the filename of a python module as a string in that same module? Otherwise, is it possible for a module to return the filename of a different module as a string? I need a program to be able to pass it's filename into an argument as a variable. I've looked through the python 3.0 sys and os library and searched Stack Overflow but I haven't turned anything up that works for Windows. I feel like it ought to be a really simple function that I'm just missing.
Asked
Active
Viewed 53 times
-4
-
Not sure why you want to, but have you tried
.__file__ – cmd Jul 20 '17 at 18:04 -
Please look at SO's [how to ask](https://stackoverflow.com/help/how-to-ask) page before asking questions and follow what it says there. SO is not a website to tell you how to do this, rather you should attempt to code something, and when you receive an error or problem, present your code, an explanation, and the problem and we will help you figure out how to fix your issue. – Professor_Joykill Jul 20 '17 at 18:06
-
Ok Professor_Joykill, well I'm here to learn, so would you explain to me what is wrong with the question? I have a program written out, but the context would hardly help the problem. It's a program that sends email notifications, and my boss requested that I try to find a way to get the module title into a variable to be sent in the email notification. Not knowing about the existence or use of a function doesn't produce an error code, so I'm failing to see what you would like me to add or remove from the question. – Ravioli Jul 22 '17 at 03:04
1 Answers
0
Yes it's possible.
For example:
import django
filename = django.__name__
I didn't find a way right now to pick the name in the own module.

Zcode
- 425
- 3
- 7