运行我的脚本时收到以下错误:
Traceback (most recent call last):
File "HC_Main.py", line 54, in <module>
setup_exists = os.path.isfile(config_file)
AttributeError: 'function' object has no attribute 'isfile'
示例代码是:
import os
setup_exists = os.path.isfile(setup_exists)
if setup_exists is False:
print "Setup file exists"
当我使用 dir(os.path)
检查 IDLE 控制台时,列出了 isfile
。此外,我也可以在 IDLE 中毫无问题地使用该函数。
会不会是我的 IDE 导致了这里的问题?我也试过在 IDE 之外运行脚本,但它仍然收到错误。
最佳答案
不知何故,os.path
不再是内置模块,而是被替换为一个函数。检查您的代码,确保您没有在某处不小心对其进行猴子修补。
对于线索,您可以先输入:
print os.path
就在您实际使用 os.path.isfile
的行之前。这应该会为您提供函数的名称,希望它能为您提供一个开始查找的好地方。
关于python - 从 os.path.isfile() 函数接收 AttributeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23573205/