Python method remove() removes the file path. If the path is a directory, OSError is raised.
Following is the syntax for remove() method:
os.remove(path)
This method does not return any value.
The following example shows the usage of remove() method.
# !/usr/bin/python import os, sys # listing directories print "The dir is: %s" %os.listdir(os.getcwd()) # removing os.remove("aa.txt") # listing directories after removing path print "The dir after removal of path : %s" %os.listdir(os.getcwd())
When we run the above program, it produces the following result:
The dir is: [ 'a1.txt','aa.txt','resume.doc','a3.py','tutorialsdir','amrood.admin' ] The dir after removal of path : [ 'a1.txt','resume.doc','a3.py','tutorialsdir','amrood.admin' ]
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.