Python Forum
Python Forum
>
General
>
News and Discussions
> a module discovering its own name
Full Version:
a module discovering its own name
You're currently viewing a stripped down version of our content.
View the full version
with proper formatting.
Skaperen
Sep-17-2019, 08:36 PM
in a module that could be renamed when installed, is there a way for it to discover its own name at the time it is imported?
Larz60+
Sep-18-2019, 12:03 AM
myname = __file__
Gribouillis
Sep-18-2019, 06:42 AM
__name__
Skaperen
Sep-19-2019, 10:33 PM
yay! they both work.
Larz60+
Sep-19-2019, 11:41 PM
__name__ is better, __file__ doesn't work in interactive mode because there is no file
Python Forum
>
General
>
News and Discussions
> a module discovering its own name