我有两个脚本:
脚本1:
from test import script2
if __name__ == '__main__':
foo()
脚本2:
^{pr2}$在结构中:
test:
│ A
│-----B:
│ script2.py
│script1.py
我试图从script1.py中的script2.py调用函数foo()
。在
我收到错误:
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
要使Python包正常工作,您需要文件夹中的
__init__.py
个文件。这些可以是空的。在然后,从子文件夹导入,因此需要
import script2 from A.B
此时,您可以使用
script2.foo()
另外值得一提的是,Python3应该是任何新项目的目标。在
相关问题 更多 >
编程相关推荐