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

Using insertAdjacentHTML instead of innerHTML to avoid XSS attacks

Quotation marks to wrap an element in HTML

Various Types of Computer Architectures