28.10.2021 Views

Python Tutorial ( PDFDrive )

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

• os.X_OK Value to include in the mode parameter of access() to determine if path can be executed.

Return Value

This method returns True if access is allowed, False if not.

Example

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

#!/usr/bin/python

import os, sys

# Assuming /tmp/foo.txt exists and has read/write permissions.

ret = os.access("/tmp/foo.txt", os.F_OK)

print "F_OK - return value %s"% ret

ret = os.access("/tmp/foo.txt", os.R_OK)

print "R_OK - return value %s"% ret

ret = os.access("/tmp/foo.txt", os.W_OK)

print "W_OK - return value %s"% ret

ret = os.access("/tmp/foo.txt", os.X_OK)

print "X_OK - return value %s"% ret

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

F_OK - return value True

R_OK - return value True

W_OK - return value True

X_OK - return value False

os.chdir(path)

Description

The method chdir() changes the current working directory to the given path.It returns None in all the cases.

Syntax

Following is the syntax for chdir() method:

os.chdir(path)

Parameters

• path -- This is complete path of the directory to be changed to a new location.

TUTORIALS POINT

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!