my_main_file.py:
from bfile import bfunc
def fna():
bfunc(sth)
if __name__ == "__main__":
fna()
bfile.py:
def bfunc(sth):
#bla bla..
错误:
name' bfunc'未定义
两个文件都在同一目录下
PS: 我在这里尝试过everythig Call a function from another file in Python
答案 0 :(得分:1)
将__init__.py
python文件添加到当前工作目录中。所以python会将目录视为包含包。您可以看到文档here
答案 1 :(得分:0)
尝试
import bfile
def fna():
bfile.bfunc(sth)
答案 2 :(得分:0)
添加export PYTHONPATH="."
到bash_profile
解决了问题