Copying contents of one file into another file in Python

File handling in Python

try:
    with open("myfile.txt", "r") as f1:
        with open("newfile.txt", "w") as f2:
            for i in f1:
                # print(type(f2))
                f2.write(i)
except:
    print("Sorry! The file does not exist. Plz create first.")
else:
    print("Contents of file copied successfully.")
Python

Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

Making GUI Calculator in Tkinter Python

Unlocking Web Design: A Guide to Mastering CSS Layout Modes