I create two python files named "test.py" and __main__.py
.
in test.py:
import __main__
in __main__.py
:
print(__name__)
but when I run test.py, it outputs nothing.
then, I change __main__.py
to:
def main():
print("ok")
and test.py:
import __main__
__main__.main()
When I run test.py, it appears an error:
Traceback (most recent call last):
File "/Users/lyz/test.py", line 2, in <module>
__main__.main()
AttributeError: module '__main__' has no attribute 'main'
who can tell me why? Thanks a lot!