What is my module name?
Rich J
crj003 at yahoo.com
Thu Jun 28 08:49:30 EDT 2001
> I have a module with a function below I
> use __name__ to return the module name.
> However, when I call the function from
> outside, it returns '__builtin__'. Is
> there a way to have this function return
> the module name regardless of where it
> is called?
>
> def myName(): return __name__
>
> Thanks!
>
> Clark
Clark,
You don't need to do that. If you want to know the name of the module
it is available after importing the module.
# Name.py
def myName():
# code for myName
...
Now all you have to do is import the module:
import Name
# And here is where you can get the name of the module
name_of_module = Name.__name__ # = 'Name'
More information about the Python-list
mailing list