我有兩個腳本:
SCRIPT1:不能導入來自不同模塊的功能在同一個項目
from test import script2
if __name__ == '__main__':
foo()
SCRIPT2:
def foo():
print 'hello'
在結構:
test:
│ A
│-----B:
│ script2.py
│script1.py
我正在試圖在腳本中調用script2.py中的函數foo()
t1.py.
我收到的錯誤:
This inspection detect names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level itesm are supported better than instance items.
我讀到的類似案件數量,但他們並沒有幫助我:
Call a function from another file in Python
How to import a function from parent folder in python?
Import Script from a Parent Directory
你需要用'__init __。py'文件將它打包。 – Artyer
您需要從'test.A.B'導入。你還需要每個文件夾中的__init __。py'文件 –
他們上面說的**或**,你將B添加到你的'PYTHONPATH'環境變量中。 – GPhilo