【发布时间】:2018-04-13 11:14:12
【问题描述】:
我正在尝试将 csv 格式转换为 tsv。 我只是用它来将逗号更改为制表符。
tsv = re.sub(',', '\t', csv)
但是我不能处理里面有逗号的字符串,例如:
dept_no,dt,hello
1,20180411,hello its me
2,20180412,here has tab
3,20180412,"here, is, commas"
有什么方法可以在不影响字符串内逗号的情况下转换成tsv?
【问题讨论】:
-
您应该使用 csv 模块来解析文件 - 它涵盖了这个和其他极端情况。