Python3 Os Remove
# Python3.x Python3 os.remove() Method
[ Python3 OS File/Directory Methods](#)
* * *
### Overview
The os.remove() method is used to delete a file at the specified path. If the specified path is a directory, it will raise an OSError.
Valid on Unix and Windows.
### Syntax
The syntax for the **remove()** method is as follows:
os.remove(path)
### Parameters
* **path** -- The path of the file to be removed.
### Return Value
This method does not return any value.
### Example
The following example demonstrates the use of the remove() method:
#!/usr/bin/python3import os, sys # List the directoryprint ("The directory is: %s" %os.listdir(os.getcwd()))# Remove os.remove("aa.txt")# List the directory after removalprint ("After removal: %s" %os.listdir(os.getcwd()))
The output of executing the above program is:
The directory is:[ 'a1.txt','aa.txt','resume.doc' ]After removal : [ 'a1.txt','resume.doc' ]
[ Python3 OS File/Directory Methods](#)
YouTip