Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How would I replace the text between \t and a second \t with something

input (not all the code):

with open(filepath) as f:
    reader = csv.reader(f, delimiter=' ')
    for line in reader:
        print(line)

output (edited):

[f34\t382\t5.00]
[f35\t42\t3.70]
[f36\t72\t1.09]
[f37\t588\t8.56]
[f38\t2837\t7.82]

Question:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How would I replace the text between \t and the second \t with ", "?

>Solution :

Would something like this work for you?

parts = line.split("\t")
result = parts[0] + "," + parts[2]

If you want to keep the tabs then the last line becomes:

result = parts[0] + "\t,\t" + parts[2]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading