如何覆盖CsvItemExporter的join_multivalued选项 [英] How to override join_multivalued option of CsvItemExporter

查看:54
本文介绍了如何覆盖CsvItemExporter的join_multivalued选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CsvItemExporter 有一个选项join_multivalued,默认为逗号(=',').

CsvItemExporter has an option join_multivalued that defaults to a comma (=',').

如何在我的草书项目中将其更改为另一个字符?

How can i change this to another char in my scrapy project?

推荐答案

通过以下方式在您的自定义CSVItemExporter中进行设置:

Set it in your custom CSVItemExporter this way:

from scrapy.conf import settings
from scrapy.contrib.exporter import CsvItemExporter

class CSVkwItemExporter(CsvItemExporter):

    def __init__(self, *args, **kwargs):
        kwargs['fields_to_export'] = settings.getlist('EXPORT_FIELDS') or None
        kwargs['encoding'] = settings.get('EXPORT_ENCODING', 'utf-8')

        super(CSVkwItemExporter, self).__init__(*args, **kwargs)

        self._join_multivalued = settings.get('MY_CSV_DELIMITER', ',')

其中MY_CSV_DELIMITER是分隔符的示例设置.

where MY_CSV_DELIMITER is an example setting you would have for a delimiter.

这篇关于如何覆盖CsvItemExporter的join_multivalued选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆