无法在同一文件夹中导入python程序
所以我开始只是看看它在哪里好玩。py这可能是错误的,或者它不能只是找到现在的打印错误,所以我需要帮助。
我在test67上的代码。py:
import os.path if not os.path.exists(fun.py): print("Alarm") if os.path.exists(fun.py): print("import")
要导入同一目录中的文件,请使用:
import fun
os.walk :
import os def find(nameofFile, path): for root, dirs, files in os.walk(path): if nameofFile in files: return os.path.join(root, nameofFile)
import sys sys.path.insert(0, pathtoFile) from fun import *
希望这有帮助。