YouTip LogoYouTip

Os Unlink

# Python2.x Python os.unlink() Method [![Image 3: Python File Methods](#) Python OS File/Directory Methods](#) * * * ### Overview The os.unlink() method is used to delete a file. If the file is a directory, it returns an error. This method is identical to [remove()](#). ### Syntax The syntax for the **unlink()** method is as follows: os.unlink(path) ### Parameters * **path** -- The path of the file to be deleted. ### Return Value This method does not return a value. ### Example The following example demonstrates the use of the unlink() method: ## Example #!/usr/bin/python # -*- coding: UTF-8 -*- import os,sys # List directory print"Directory is: %s" %os.listdir(os.getcwd()) os.unlink("aa.txt") # Directory after deletion print"Directory after deletion: %s" %os.listdir(os.getcwd()) The output of executing the above program is: Directory is: [ 'a1.txt','aa.txt','resume.doc']Directory after deletion: [ 'a1.txt','resume.doc' ] [![Image 4: Python File Methods](#) Python OS File/Directory Methods](#)
← Linux Comm HeadDjango Cookie Session β†’