代码如下:
def _parse(self, row):
data = []
comments = []
for cell in row:
cell = self._collapse_whitespace(cell)
if cell.startswith('#') and not comments:
comments.append(cell[1:])
elif comments:
comments.append(cell)
else:
data.append(cell)
return self._purge_empty_cells(data), self._purge_empty_cells(comments)
当时__init__是类的构造函数,他将得到有_parse解析回来的多个返回值,self._purge_empty_cells(data) 赋给self.cells, self._purge_empty_cells(comments)赋给self.comments
就这么简单 :)