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

Using insertAdjacentHTML instead of innerHTML to avoid XSS attacks

Guess The Number Game - You vs. Your Friend