如何在 Python 和/或 Cloud9 IDE 中抑制 warning/error?
How do you suppress a warning/error in Python and or Cloud9 IDE?
我正在使用 Cloud9 IDE 并创建了一个 Python 项目。
但是,我在我的编辑器中一直在一行中收到错误,当我 运行 它时这不是错误,它说:
Instance of 'dict' has no 'columns' member
如何使用 Python 语法或 Cloud9 语法抑制此错误?
注意:当我 运行 代码时,它不会导致错误。我的 IDE 编辑只是认为这是一个错误并警告我。
xl = pd.ExcelFile(dataFileUrl)
sheets = xl.sheet_names
data = xl.parse(sheets[0])
# the ERROR warning is on the line for data.columns
for ecol in expectedCols:
if (ecol in data.columns) == False:
return {
'fail': True,
'code': 402,
'msg': "Incomplete data. Missing: " + ecol
}
您可以使用try
(等同于其他语言的try/catch或rescue/ensure)
try:
ecol in data.columns:
except:
#Handle differently if there is a problem or pass
return {
'fail': True,
'code': 402,
'msg': "Incomplete data. Missing: " + ecol
}
根据@LucG 的评论,我尝试以不同的方式获取列 headers 的列表。
因此遵循this thread,我使用了
list(df)
而不是
df.columns
这抑制了警告。
这是 PyLint 的一个已知限制,正如他们在 documentation..
中提到的
E1101
%s %r has no %r member
Function %r has no %r member
Variable %r has no %r member
. . .
Description
Used when an object (variable, function, …) is accessed for a non-existent member.
False positives: This message may report object members that are created dynamically, but exist at the time they are accessed.
尝试在页面顶部添加评论 # pylint: disable=no-member
(我以前从未尝试过修改 PyLint,所以我完全确定这个通过评论配置的系统是如何工作的...... )
我正在使用 Cloud9 IDE 并创建了一个 Python 项目。
但是,我在我的编辑器中一直在一行中收到错误,当我 运行 它时这不是错误,它说:
Instance of 'dict' has no 'columns' member
如何使用 Python 语法或 Cloud9 语法抑制此错误?
注意:当我 运行 代码时,它不会导致错误。我的 IDE 编辑只是认为这是一个错误并警告我。
xl = pd.ExcelFile(dataFileUrl)
sheets = xl.sheet_names
data = xl.parse(sheets[0])
# the ERROR warning is on the line for data.columns
for ecol in expectedCols:
if (ecol in data.columns) == False:
return {
'fail': True,
'code': 402,
'msg': "Incomplete data. Missing: " + ecol
}
您可以使用try
(等同于其他语言的try/catch或rescue/ensure)
try:
ecol in data.columns:
except:
#Handle differently if there is a problem or pass
return {
'fail': True,
'code': 402,
'msg': "Incomplete data. Missing: " + ecol
}
根据@LucG 的评论,我尝试以不同的方式获取列 headers 的列表。
因此遵循this thread,我使用了
list(df)
而不是
df.columns
这抑制了警告。
这是 PyLint 的一个已知限制,正如他们在 documentation..
中提到的E1101
%s %r has no %r member Function %r has no %r member Variable %r has no %r member . . .Description
Used when an object (variable, function, …) is accessed for a non-existent member.
False positives: This message may report object members that are created dynamically, but exist at the time they are accessed.
尝试在页面顶部添加评论 # pylint: disable=no-member
(我以前从未尝试过修改 PyLint,所以我完全确定这个通过评论配置的系统是如何工作的...... )