KnowledgeBoat Logo

Computer Science

Write a program that appends the contents of one file to another. Have the program take the filenames from the user.

Python File Handling

4 Likes

Answer

def append_file(f1, f2):
    with open(f1, 'r') as source:
        with open(f2, 'a') as destination:
            destination.write(source.read())
    
source_file = input("Enter the name of the source file: ")
destination_file = input("Enter the name of the destination file: ")

append_file(source_file, destination_file)

Answered By

3 Likes


Related Questions