Solution: Append One File's Contents to the End of Another
Learn how to append the contents of one file to the end of another.
We'll cover the following...
The solution to the problem of appending the contents of one file to the end of another is given below.
Solution
Press + to interact
main.py
file2.txt
file1.txt
# Append filesf1 = open('file1.txt', 'r')para1 = ''while True :data = f1.readline( )if data == '' :breakpara1 += dataf2 = open('file2.txt', 'r+')para2 = ''while True :data = f2.readline( )if data == '' :breakpara2 += datapara2 += para1f2.seek(0, 0)f2.write(para2)f1.close( )f2.close( )f2 = open('file2.txt', 'r')para2 = ''while True :data = f2.readline( )if data == '' :breakpara2 += dataprint(para2)f2.close( )