28.10.2021 Views

Python Tutorial ( PDFDrive )

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

# !/usr/bin/python

import os

src = '/usr/bin/python'

dst = '/tmp/python'

# This creates a symbolic link on python in tmp directory

os.symlink(src, dst)

# Now let us use readlink to display the source of the link.

path = os.readlink( dst )

print path

Let us compile and run the above program, this will create a symblic link to /usr/bin/python and later it will read the

source of the symbolic link using readlink() call. Before running this program, make sure you do not have

/tmp/python already available.

/usr/bin/python

os.remove(path)

Description

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

Syntax

Following is the syntax for remove() method:

os.remove(path)

Parameters

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

Return Value

This method does not return any value.

Example

The following example shows the usage of remove() method.

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

Let us compile and run the above program, this will produce the following result:

The dir is:

TUTORIALS POINT

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!