How to Delete a File in Python


In this example we will show how to delete a file in Python.

Source Code

import os

os.remove('filename.py')

Output:

If the file exists, delete it without prompting.
If the file does not exist, a 'FileNotFoundError' error is thrown.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments