xxxxxxxxxx
Write a Python program to
Read the first two lines from a text file named "file1.txt"
Write the two lines read from "file1.txt" to a new file called "file2.txt"
Read "file2.txt" and Print the contents
Answer:(penalty regime: 10, 20, %)
xxxxxxxxxx
def read_lastnlines(fname,n):
with open('file1.txt') as f:
for line in (f.readlines() [-n:]):
print(line)
read_lastnlines('file1.txt',3)
xxxxxxxxxx
Write a Python program to
Read the first two lines from a text file named "file1.txt"
Write the two lines read from "file1.txt" to a new file called "file2.txt"
Read "file2.txt" and Print the contents
Answer:(penalty regime: 10, 20, %)
xxxxxxxxxx
Write a Python program to
Read the first two lines from a text file named "file1.txt"
Write the two lines read from "file1.txt" to a new file called "file2.txt"
Read "file2.txt" and Print the contents
xxxxxxxxxx
fhandle1 = open("file1.txt","r")
fhandle2 = open("file2.txt","w")
str = fhandle1.readline()
fhandle2.write(str)
str = fhandle1.readline()
fhandle2.write(str)
fhandle1.close()
fhandle2.close()
fhandle3 = open("file2.txt")
print(fhandle3.read())
fhandle3.close()