You are here : python_2ososremove

os.remove() - os

             

The method remove() removes the file path. If the path is a directory, OSError is raised.


  • path -- This is the path, which is to be removed.


Syntax


os.remove(path)


Example


# !/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())


Output / Return Value

When we run above program, it produces 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' ]


Limitations


Alternatives / See Also


Reference