Exemplo n.º 1
0
def to_csv(input, output):
    content = open(input, "rt", encoding='utf-8').read()
    # 将输入的信息进行清洗,去掉一些不需要的回车符号
    j = ujson.loads(content.replace("\\r", '').replace("\\n", ''))

    # 转换成csv格式的字符串
    transformed = transform(list(j.values()))
    with open(output, "wt", encoding='utf-8') as f:
        f.write(transformed)
Exemplo n.º 2
0
    def test_simple_data_missing_key_first(self):
        data = [{
            'key_1': 'value 1',
        }, {
            'key_1': 'value 3',
            'key_2': 'value 4'
        }]

        self.assertEqual(transform(data),
                         'key_1,key_2\nvalue 1,\nvalue 3,value 4\n')