File Handling 7: Copy File

# Copy file

fs = open("ipt.txt", "r")
fd = open("opt.txt", "w+")

while(True):
Line = fs.readline()
if not Line:
break
fd.write(Line)

print("file copied")

print("displaying copied file:")
fd.seek(0,0)
while(True):
Line = fd.readline()
if not Line:
break
print(Line)

fs.close()
fd.close()


# Copy file

fs = open("ipt.txt", "r")
fd = open("opt.txt", "w+")

L = fs.readlines()
for Line in L:
fd.write(Line)

print("file copied")

print("displaying copied file:")
fd.seek(0,0)

L = fd.readlines()
for Line in L:
print(Line)

fs.close()
fd.close()

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu