我正在编写python脚本,但我只是在python 3.x中遇到了有关pylint检查的问题:
class m(object):
def check_infile(self):
infile = None
if not isinstance(infile, file):
print("infile variable is not a file type.")输出:
E: 56,38: Undefined variable 'file' (undefined-variable)我试图通过添加# pylint: disable=E0602, undefined-variable, E0603来消除这个问题,但是没有任何帮助。有什么建议吗?
发布于 2016-04-11 15:22:20
在python3.x中,file不是有效类型:
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> file
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'file' is not defined所以皮林特就在这里,你可能不想让它安静下来。您可能需要检查对象是否具有类似文件的方法:
if not getattr(infile, 'read', None):
print('definitely not a file...')https://stackoverflow.com/questions/36552767
复制相似问题