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
TSV is a file type where fields are separated by tab.
If you want to convert a TSV into a CSV (comma separated value) you just need to do a find and replace from TAB to COMMA.
Update:
As pointed out by don-roby, "There might be commas in the tsv", for that we use a regex to escape all the csv special characters as defines by rfc4180.
i.e.:
import re
tsv = open('tsv.tsv', 'r')
fileContent = tsv.read()
appDesc = re.sub("""(?ism)(,|"|')""", r"\\\1", appDesc) # escape all especial charaters (" ' ,) rfc4180
fileContent = re.sub("\t", ",", fileContent) # convert from tab to comma
csv_file = open("csv.csv", "w")
csv_file.write(fileContent)
csv_file.close()