'How to print a module name in Python?
How do you print a module name in Python?
I tried to import a module and print it, then it gives me <module 'time' (built-in)>.
import time
print(time) # <module 'time' (built-in)>
How to print just the module name?
Solution 1:[1]
The name of a module as a string is available as its __name__ attribute.
>>> import time
>>> print(time.__name__)
time
This is shown in the Tutorial, by the way.
Solution 2:[2]
Simply import a module and print its name using _name
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mkrieger1 |
| Solution 2 |
