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.")

    

Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

What is the difference between iostream and iostream.h in cpp?

The Basic Structure of a Full-Stack Web App