How do you suppress a warning/error in Python and or Cloud9 IDE?
我正在使用cloud9 ide并创建了一个python项目。
但是,我总是在一行上获取编辑器中的错误,这在运行它时不是错误,它表示:
1 | Instance of 'dict' has no 'columns' member |
如何使用python语法或cloud9语法来抑制此错误?
注意:当我运行代码时,它不会导致错误。我的IDE编辑器只是认为这是一个错误并警告我。
1 2 3 4 5 6 7 8 9 10 11 12 13 | 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 } |
这是他们文档中提到的Pylint的已知限制。
E1101
1
2
3
4
5 %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.
尝试在页面顶部添加注释
在@lugg的评论之后,我尝试以不同的方式获取列标题列表。
因此,按照这个思路,我使用
1 | list(df) |
而不是
1 | df.columns |
这抑制了警告。
您可以使用
1 2 3 4 5 6 7 8 9 | 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 } |