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.

• stat.S_IRGRP: Read by group.

• stat.S_IWGRP: Write by group.

• stat.S_IXGRP: Execute by group.

• stat.S_IRWXO: Read, write, and execute by others.

• stat.S_IROTH: Read by others.

• stat.S_IWOTH: Write by others.

• stat.S_IXOTH: Execute by others.

Syntax

Following is the syntax for chmod() method:

os.chmod(path, mode);

Parameters

• path -- This is the path for which mode would be set.

• 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 chmod() method:

#!/usr/bin/python

import os, sys, stat

# Assuming /tmp/foo.txt exists, Set a file execute by the group.

os.chmod("/tmp/foo.txt", stat.S_IXGRP)

# Set a file write by others.

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

print "Changed mode successfully!!"

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

Changed mode successfully!!

os.chown(path, uid, gid)

Description

The method chown() changes the owner and group id of path to the numeric uid and gid. To leave one of the ids

unchanged, set it to -1.To set ownership, you would need super user privilege..

Syntax

Following is the syntax for chown() method:

os.chown(path, uid, gid);

TUTORIALS POINT

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!