Python Programming - Reading and Writing Files - Discussion

Discussion Forum : Reading and Writing Files - General Questions (Q.No. 44)
44.
How can you copy a file named "source.txt" to a new location and rename it as "destination.txt"?
copy_file("source.txt", "destination.txt")
shutil.copy("source.txt", "destination.txt")
with open("destination.txt", "w") as dest:
    dest.write(open("source.txt").read())
rename_file("source.txt", "destination.txt")
Answer: Option
Explanation:
Using shutil.copy() to copy and rename a file.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.