[英]How do you suppress a warning/error in Python and or Cloud9 IDE?
I am using the Cloud9 IDE and have created a Python project. 我正在使用Cloud9 IDE,并创建了一个Python项目。
However, I keep getting the error in my editor on one line, which is not an error when i run it, which says: 但是,我一直在编辑器中的一行上收到错误,这不是运行时的错误,它说:
Instance of 'dict' has no 'columns' member
How can I suppress this error, either using Python syntax or Cloud9 syntax? 如何使用Python语法或Cloud9语法抑制此错误?
NOTE: when I run the code, it does not result in an error. 注意:当我运行代码时,它不会导致错误。 My IDE editor simply thinks its an error and warns me.
我的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
}
This is a known limitation of PyLint as mentioned in their documentation .. 如其文档中所述,这是PyLint的已知限制。
E1101
E1101
%s %r has no %r member%s%r没有%r个成员\n\nFunction %r has no %r member
函数%r没有%r成员\nVariable %r has no %r member
变量%r没有%r成员\n.
。 .
。 .
。
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.
误报:此消息可能报告动态创建的对象成员,但在访问对象成员时就存在。
Try adding the comment # pylint: disable=no-member
at the top of your page (I've never played around with modifying PyLint before, so I'm note entirely sure how this system of configuring via comments works...) 尝试在页面顶部添加注释
# pylint: disable=no-member
(我以前从没玩过修改PyLint的操作,因此我完全确定了通过注释进行配置的系统是如何工作的...)
You can use try
(equivalent to try/catch or rescue/ensure in other languages) 您可以使用
try
(相当于其他语言的try / catch或抢救/确保)
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
}
Following the comment by @LucG, I tried to get the list of column headers in a different way. 在@LucG发表评论之后,我尝试以其他方式获取列标题列表。
Hence following this thread , I used 因此,遵循此线程 ,我用
list(df)
instead of 代替
df.columns
This suppressed the warning. 这抑制了警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.