Professional Documents
Culture Documents
File Handling A) Count The Number of Lines in The Given File
File Handling A) Count The Number of Lines in The Given File
File Handling A) Count The Number of Lines in The Given File
File Handling
b) Copy the contents of file1 to file2 and display the contents of both on the
screen.
with open("test.txt") as f1:
print ("Contents of File 1:\n",f1.read())
with open("test.txt") as f:
with open("out.txt", "w") as f1:
for line in f:
f1.write(line)
with open("out.txt") as f2:
print ("Contents of File 2 after copying File 1:\n",f2.read())