python - 从 os.path.isfile() 函数接收 AttributeError

标签 python python-2.7 pyscripter

运行我的脚本时收到以下错误:

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/

相关文章:

python - 如何让python程序在每次下载文件时自动运行?

python - 尝试使用 pip 安装 PIL 时出错以及 pyscripter 错误

python - 如何通过输入的更改来自动化单行代码?

python - 在 Mac OS 上使用 virtualenvwrapper 在 python 版本之间切换

python-3.x - 关于 PyScripter 中 python 解释器的字体

python - numpy 中的矩阵加法

python - 如何在 GdkPixbuf.Pixbuf 上渲染文本

python - 值错误 : array is too big

python - Python2.7 找不到 psycopg2 模块