How to read a file line by line and copied to another file in Python

1 Answer

0 votes
filename = "data.txt"

file = open(filename, "w")
file.write("Python is an interpreted high-level general-purpose\n"
           "Artificial Intelligence\t covers three types of tasks\n"
           "emphasizes code readability\t with its use of significant\t")

file2 = open("copydata.txt", "w")

with open(filename, mode='r') as file:
    for line in file:
        file2.write(line)

file2 = open("copydata.txt", "r")
print(file2.read())






'''
run:

Python is an interpreted high-level general-purpose
Artificial Intelligence  covers three types of tasks
emphasizes code readability      with its use of significant

'''

 



answered Oct 5, 2021 by avibootz
...