Home > Software design >  How to print a module name in Python?
How to print a module name in Python?

Time:04-11

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?

CodePudding user response:

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.

CodePudding user response:

Simply import a module and print its name using _name

  • Related