How to import a function from another directory file in python. Even have __init__.py file in that directory?
本问题已经有最佳答案,请猛点这里访问。
我有如下目录结构……
1 2 3 4 5 6 | |---- folder1 |---- __init__.py |---- python_file1.py |---- folder2 |---- __init__.py |---- python_file2.py |
当我尝试像这样导入"folder2.python_file2 import some_function"时。
它给出一个错误:importError:无法导入名称某些函数
另外,在堆栈溢出中,我看到了许多答案,他们说如果目录没有
谢谢。
(P)Python uses a period()operator to refer to the directories/modules starting from the current folder and moving upwards in the directory tree with each period.For example,if you wish to import a file from python e e u file2.py and the file you are importing is contained in folder2 itself.This can be achieved by-EDOCX1 plography 0/sil if you wish to import a file from Python===================================================希望这帮助。(p)