Easy Tutorial
❮ Python Remove Duplicate From List Python Os Minor ❯

Python3 os.remove() Method

Python3 OS File/Directory Methods


Overview

The os.remove() method is used to delete the file at the specified path. If the specified path is a directory, an OSError will be raised.

Valid in Unix, Windows.

Syntax

The syntax for the remove() method is as follows:

os.remove(path)

Parameters

Return Value

This method does not return any value.

Example

The following example demonstrates the use of the remove() method:

#!/usr/bin/python3

import os, sys

# List directory
print ("Directory is: %s" %os.listdir(os.getcwd()))

# Remove
os.remove("aa.txt")

# List directory after removal
print ("After removal: %s" %os.listdir(os.getcwd()))

Executing the above program will output:

Directory is:
[ 'a1.txt','aa.txt','resume.doc' ]
After removal: 
[ 'a1.txt','resume.doc' ]

Python3 OS File/Directory Methods

❮ Python Remove Duplicate From List Python Os Minor ❯