How do I convert a .tsv to .csv?

后端 未结 4 2071
旧时难觅i
旧时难觅i 2020-12-17 00:46

Trying to convert a .tsv to a .csv. This:

import csv

# read tab-delimited file
with open(\'DataS1_interactome.tsv\',\'rb\') as fin:
    cr = csv.reader(fin         


        
4条回答
  •  一生所求
    2020-12-17 01:30

    While attempting to write to the CSV file, it encounters a token where it has to insert an escape character. However, you have not defined one.

    Dialect.escapechar

    A one-character string used by the writer to escape the delimiter if quoting is set to QUOTE_NONE and the quotechar if doublequote is False. On reading, the escapechar removes any special meaning from the following character. It defaults to None, which disables escaping.

    Source: https://docs.python.org/2/library/csv.html#csv.Dialect.escapechar

    Example code:

    # write comma-delimited file (comma is the default delimiter)
    with open('interactome.csv','wb') as fou:
        cw = csv.writer(fou, quotechar='', quoting=csv.QUOTE_NONE, escapechar='\\')
        cw.writerows(filecontents)
    

提交回复
热议问题