使用 python 标头标记 txt 文件

问题描述

Python 对我来说是一门新语言,我在将原始数据制表到 txt 文件时遇到了一些困难。我想离开如下:

ID,company_name,cnpj
1123,'XPTO',123456478
4354,'WWWW',243425566

我在txt文件中的数据如下:
{'_id': {'$oid': '5c597e54b74db23f476e0db4'},'company_name': 'CALTABIANO MOTORS PINHEIROS LTDA','cnpj': '987654321111','description': '206-2 - Sociedade Empresária Limitada','telephone': '(11) 3660-7084','andress': 'Rua Major Quedinho 90','zip_code': '05.477-000','city': 'SAO PAULO','state': 'SP','address': 'AV DOUTORA RUTH CARDOSO','option': 'save'}{'_id': {'$oid': '5c59eb24b74db279878f3806'},'company_name': 'KCC','cnpj': '0000000000000','description': 'xxx','telephone': '00000000','zip_code': '0000000','city': 'São Paulo','state': 'São Paulo'}

我的代码

with open(filename_txt,'w') as arquivo:
    for client in data_clients:
        arquivo.write(str(client))
        #print(client)
    arquivo.close()


with open(filename_txt) as f:
    reader = csv.reader(f,delimiter="\n")
    for i in f:
        reader1=csv.reader(f,delimiter=";")
        print(i)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)