base.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:knesset-data-datapackage 作者: hasadna 项目源码 文件源码
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])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号