Pythonic方法将连接与CSV writerow结合起来

时间:2016-01-13 00:26:06

标签: python join export-to-csv

我有两个CSV行,我只想迭代一次。请注意,他们结合了两个模型,库存和材料。我怎么能将这两个表组合成一个单独的csv导出?

表:

[outcsv.writerow([getattr(curr.material, column.name) for column in Material.__mapper__.columns]) for curr in records]

加入:

 var result = obj.map(function (item) {
  var filterLabels = function (label) {
    return label.label !== '' && label.num !== '';
  };
  item.TestTool = item.TestTool.filter(filterLabels);
  item.TestItv  = item.TestItv.filter(filterLabels);
  return item;
});

// console.log(JSON.stringify(result));

1 个答案:

答案 0 :(得分:1)

哦,这很简单。

[outcsv.writerow([getattr(curr, column.name) for column in Inventory.__mapper__.columns] + [getattr(curr.material, column.name) for column in Material.__mapper__.columns]) for curr in records]