對不起,這絕對是重複的,但我找不到答案。我在Python 3個工作,這是我的應用程序的結構:如何導入Python文件?
/home
common.py
australia/
new-south-wales/
fetch.py
我在home/
目錄,運行fetch.py
。如何在該腳本中導入common.py
中的函數?
我已經設置了fetch.py
如下:
from common import writeFile
,但我得到了以下錯誤:
File "australia/new-south-wales/fetch.py", line 8, in <module>
from common import writeFile
ModuleNotFoundError: No module named 'common'
如果我只是做python -c "from common import writeFile"
我沒有看到一個錯誤。
不應該翻譯look in the current directory for modules?
你錯過了一個'__init __ py'爲模塊。 https://docs.python.org/3/tutorial/modules.html#packages –