Which object is the property of _ _ name__ in python? Is it equivalent to self.__name__?

print(__name__,type(__name__))

result: _ _ main__ < class" str" >
my question is, which object"s attribute is _ _ name__? Is it equivalent to self.__name__? Or thismodule.__name__?

after the wind blows, it is sure enough

import pandas as pd
print(pd.__name__)

pandas

May.09,2022

the name of the current main program


_ _ name__ is a built-in variable whose value is obtained by the name of the evaluation module / package. So if you import a module / package, it is naturally the name of the module / package. But if you run a python file directly, _ _ name__ is _ _ main__ when running as a top-level script. So you will often see

if __name__ == '__main__':
 code_block
As a rule, if you are designing a functional module, in other words, if you want to be imported by the user, then you should implement a simple unit test or sanity check in the code_block above. Because this part of the code will not trigger during import. It is triggered only when it is run directly.

after the wind blew, the god hinted and did the test again, and sure enough:

import pandas as pd
print(pd.__name__)
< hr >

pandas

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ed095e-507b1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ed095e-507b1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?