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.

• mode -- This may take one of the above mentioned values or bitwise ORed combinations of them.

Return Value

This method does not return any value.

Example

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

#!/usr/bin/python

import os, sys

# Open a file

path = "/var/www/html/foo.txt"

fd = os.open( path, os.O_RDWR|os.O_CREAT )

# Close opened file

os.close( fd )

# Now change the file mode.

# Set a file execute by group.

os.lchmod( path, stat.S_IXGRP)

# Set a file write by others.

os.lchmod("/tmp/foo.txt", stat.S_IWOTH)

print "Changed mode successfully!!"

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

print "Changed mode successfully!!"

os.lchown(path, uid, gid)

Description

The method lchown() changes the owner and group id of path to the numeric uid and gid. This function will not

follow symbolic links. To leave one of the ids unchanged, set it to -1. .

Syntax

Following is the syntax for lchown() method:

os.lchown(path, uid, gid)

Parameters

• path -- This is the file path for which ownership to be set.

• uid -- This is the Owner ID to be set for the file.

• gid -- This is the Group ID to be set for the file.

Return Value

This method does not return any value.

TUTORIALS POINT

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!