def _append(self, row, **make_kwargs):
if not self._skip_resource(**make_kwargs):
# append a row (with values in native python format) to the csv file (creates the file and header if does not exist)
if not self.csv_path:
raise Exception('cannot append without a path')
fields = self.descriptor["schema"]["fields"]
if not hasattr(self, "_csv_file_initialized"):
self._csv_file_initialized = True
self.logger.info('writing csv resource to: {}'.format(self.csv_path))
with open(self.csv_path, 'wb') as csv_file:
unicodecsv.writer(csv_file, encoding="utf-8").writerow([field["name"] for field in fields])
with open(self.csv_path, 'ab') as csv_file:
unicodecsv.writer(csv_file, encoding="utf-8").writerow([uncast_value(row[field["name"]], field) for field in fields])
评论列表
文章目录