I am new to Python. I have two files that have sentences that I need to combine 2 files line by line into a single file.
file_1.txt:
feel my cold hands.
I love oranges.
Mexico has a large surplus of oil.
Ink stains don't rub out.
file_2.txt:
≥ª ¬˘ º’¿ª ¡ª ∏∏¡Æ∫¡.
∏«¸ ∫Ò«‡±‚∞° ∞≠¿ª ≥Øæ∆∞¨¥Ÿ.
∏flΩ√ƒ⁄ø°¥¬ ¥Ÿ∑Æ¿« ø©∫–¿« ºÆ¿Ø∞° ¿÷¥Ÿ.
¿◊≈© ¿⁄±π¿∫ ¥€æ∆µµ ¡ˆøˆ¡ˆ¡ˆ æ ¥¬¥Ÿ.
FINAL OUTPUT should look like:
feel my cold hands.
≥ª ¬˘ º’¿ª ¡ª ∏∏¡Æ∫¡.
I love oranges.
∏«¸ ∫Ò«‡±‚∞° ∞≠¿ª ≥Øæ∆∞¨¥Ÿ.
Mexico has a large surplus of oil.
∏flΩ√ƒ⁄ø°¥¬ ¥Ÿ∑Æ¿« ø©∫–¿« ºÆ¿Ø∞° ¿÷¥Ÿ.
Ink stains don't rub out.
¿◊≈© ¿⁄±π¿∫ ¥€æ∆µµ ¡ˆøˆ¡ˆ¡ˆ æ ¥¬¥Ÿ.
Here is what I tried
filenames = ['data/data.txt', 'data/data2.txt']
with open('data/test.txt', 'w') as outfile:
for fname in filenames:
with open(fname) as infile:
for line in infile:
outfile.write(line)
This code here just concats the files one after another. However, it is not paring up the line by line and creating \n. Thanks!!
References: combine multiple text files into one text file using python