我有两个脚本:
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