YouTip LogoYouTip

Os Remove

# Python2.x Python os.remove() Method [![Image 3: Python File Methods](#) Python 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, an OSError will be raised. This method is identical to [unlink()](#). Valid on Unix, 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 a value. ### Example The following example demonstrates the use of the remove() method: #!/usr/bin/python# -*- coding: UTF-8 -*-import os, sys # List directoryprint "Directory: %s" %os.listdir(os.getcwd())# Remove os.remove("aa.txt")# List directory after removalprint "After removal: %s" %os.listdir(os.getcwd()) Executing the above program yields the following output: Directory: [ 'a1.txt','aa.txt','resume.doc' ]After removal: [ 'a1.txt','resume.doc' ] [![Image 4: Python File Methods](#) Python OS File/Directory Methods](#)
← Os RemoveOs Read β†’