-1

I have a file with level, equation and answer (separated by tabs), for a math game. For example:

Lvl Eq Ans 2 2*6 12 

How can I replace the tab space by a comma , in a new file?

2
  • 2
    If you want to, what's stopping you? Ask a specific question Commented Jul 3, 2016 at 20:17
  • @AndrewL. Sorry for my idiotic way of asking Commented Jul 3, 2016 at 20:23

2 Answers 2

15

Read the lines from the old file and replace '\t' with ',' in the new file. This should do:

with open('oldfile.txt') as fin, open('newfile.txt', 'w') as fout: for line in fin: fout.write(line.replace('\t', ',')) 
Sign up to request clarification or add additional context in comments.

Comments

3

Use the str.replace() method like this:

>>> s = '2\t2*6\t12' >>> print s 2 2*6 12 >>> s.replace('\t', ',') 2,2*6,12 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.