๐Ÿ
B.TECH I YEAR โ€ข II SEMESTER โ€ข R25

Python Programming - Lab Manual

Python Programming Laboratory โ€ข Program Solution

๐Ÿ“˜ R25 Regulation ๐ŸŽ“ I Year ๐Ÿ“š II Semester ๐Ÿ Python Programming ๐Ÿงช Lab Program
Selected Program

merge two given file contents

โ† All Python Programs

Aim:

☛   Write a Python code to merge two given file contents into a third file.

Solution :


PROGRAM: (merge_files.py)

 
# Open the source text file - 1
file1 = open('one.txt','r')
content1 = file1.read()
file1.close()
# Open the source text file - 2
file2 = open('two.txt','r')
content2 = file2.read()
file2.close()
# Open the destination file to merge content
file3 = open('three.txt','w')
file3.write(content1 + content2 )
file3.close()
# Print merge text file
file3 = open('three.txt','r')
print(file3.read())
file3.close()

OUTPUT:

 
Hai Study Glance
How are You?

image
image
image

๐Ÿ’ป Run This Python Program

merge two given file contents
The selected Python program is loaded automatically into the editor. Edit the program, provide input if required and click Run.

The compiler is embedded using OneCompiler. Your Python program runs inside the embedded Python environment; Study Glance does not execute Python code directly on your web server.
โ† Back to Python Lab Programs ๐Ÿ“š All Lab Manuals