0

Is there a better way to join files?

I have two files that I want to merge:

File 1: AccountNo, firstName, lastName 12, Peter, Smith 14, Mary, Smith

File 2: AccountNo, Payment, Invoice 12, 15.00, 1000 14, 15.10, 1001

I would like to join the files into one: AccountNo, firstName, lastName, Payment, Invoice 12, Peter, Smith, 15.00, 1000 14, Mary, Smith, 15.10, 1001

I'm using Python 3.3

with open('names.txt', 'r') as names:
    with open('accounts.txt', 'r') as accts:
        with open('combined.txt', 'w') as outfile:
            n = n.readline()
            a = a.readline()
            outFile.write(n.replace('\n', '\t') + a)

Not sure this is the best way to do this, or if there is a better way to go about it.

Thanks!

1 Answers1

0

I would check this question out, which may answer your question. Most answers give a similar response to your code, using with.

Community
  • 1
  • 1
TheDarkTurtle
  • 413
  • 1
  • 3
  • 12