How to remove a file using Python?

PythonServer Side ProgrammingProgramming

You can delete a single file or a single empty folder with functions in the os module. For example, if you want to delete a file a.txt,

>>> import os
>>> os.remove('a.txt')

The argument to os.remove must be absolute or relative path. You can also use the os.unlink() remove files. For example,

>>> import os
>>> os.unlink('a.txt')
raja
Updated on 18-Feb-2020 04:57:20

Advertisements