Python os.unlink () method
Python OS file / directory methods
Outline
os.unlink () method is used to delete a file, if the file is a directory returns an error.
grammar
unlink () method syntax is as follows:
os.unlink(path)
parameter
Delete the file path- path
return value
This method has no return value.
Examples
The following example demonstrates the unlink () method of use:
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 列出目录 print "目录为: %s" %os.listdir(os.getcwd()) os.unlink("aa.txt") # 删除后的目录 print "删除后的目录为 : %s" %os.listdir(os.getcwd())
The above program output is:
目录为: [ 'a1.txt','aa.txt','resume.doc'] 删除后的目录为 : [ 'a1.txt','resume.doc' ]