Deleting a file in Python

We need os module to delete a file on hard drive

import os
if os.path.exists("myfile.txt"):
    os.remove("myfile.txt")
    print("Deleted successfully")
else:
    print("No such file exists")

    

Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

The Basic Structure of a Full-Stack Web App

Unlocking Web Design: A Guide to Mastering CSS Layout Modes