How to use file handling to read and write In Python
In this method, we would be using βrβ mode(to read the file) in the first file and βwβ mode(to write in a file) in the second file. Finally, we will write the content of the first file into the second file by using the write method. We will use the upper method there to capitalize the content while writing the content into the second file.
Python
# To open the first file in read mode f1 = open ( "sample file 1.txt" , "r" ) # To open the second file in write mode f2 = open ( "sample file 2.txt" , "w" ) # For loop to traverse through the file for line in f1: # Writing the content of the first # file to the second file # Using upper() function to # capitalize the letters f2.write(line.upper()) |
Output:
Python β Copy all the content of one file to another file in uppercase
In this article, we are going to write a Python program to copy all the content of one file to another file in uppercase. In order to solve this problem, letβs see the definition of some important functions which will be used: