标签:ini code mod call lnl 无法 module python3 nbsp
[wangml@iZwz976helaylvgqok97prZ pythoncode]$ ls Test __init__.py __pycache__ Top.py [wangml@iZwz976helaylvgqok97prZ Test]$ cat Top.py def top(): print("Top!") return
[wangml@iZwz976helaylvgqok97prZ pythoncode]$ cat Test.py import Test Test.Top.top() 执行Test.py这个文件,我们会看到什么呢?是输出 "Top!" 吗? [wangml@iZwz976helaylvgqok97prZ pythoncode]$ python3 Test.py Traceback (most recent call last): File "Test.py", line 2, in <module> Test.Top.top() AttributeError: module ‘Test‘ has no attribute ‘Top‘
[wangml@iZwz976helaylvgqok97prZ Test]$ cat __init__.py
[wangml@iZwz976helaylvgqok97prZ Test]$ vim __init__.py [wangml@iZwz976helaylvgqok97prZ Test]$ cat __init__.py from Test import Top [wangml@iZwz976helaylvgqok97prZ Test]$ cd ../ [wangml@iZwz976helaylvgqok97prZ pythoncode]$ python3 Test.py Top!
标签:ini code mod call lnl 无法 module python3 nbsp
原文地址:https://www.cnblogs.com/lnlin/p/9129222.html