Python has built-in open() method to open a file or create a file object. It is used for reading, writing and appending of an opened file. The open() is a factory method that creates file object.
Syntax of Python open()
open(path, mode)
Here, path is the path of file and mode parameter is an access modifier which tells the purpose of opening a file, like read, write etc.
This is the following solution to read content from one file and write in another file-
def readwrite():
readfile = open('first.txt', 'r')
writefile = open('second.txt', 'w')
for line in readfile:
line = line.upper()
writefile.write(line)
readfile.close()
writefile.close()
readwrite()
The above code reads the data from the 'first.txt' and write them on 'second.txt'.
Solution
Python has built-in open() method to open a file or create a file object. It is used for reading, writing and appending of an opened file. The open() is a factory method that creates file object.
Syntax of Python open()
open(path, mode)Here, path is the path of file and mode parameter is an access modifier which tells the purpose of opening a file, like read, write etc.
This is the following solution to read content from one file and write in another file-
The above code reads the data from the 'first.txt' and write them on 'second.txt'.
need an explanation for this answer? contact us directly to get an explanation for this answer