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.

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 flag.

ret = os.lchflags(path, os.UF_IMMUTABLE )

print "Changed file flag successfully!!"

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

Changed file flag successfully!!

os.lchmod(path, mode)

Description

The method lchmod() changes the mode of path to the numeric mode. If path is a symlink, this affects the

symlink rather than the target.

The mode may take one of the following values or bitwise ORed combinations of them:

• stat.S_ISUID: Set user ID on execution.

• stat.S_ISGID: Set group ID on execution.

• stat.S_ENFMT: Record locking enforced.

• stat.S_ISVTX: Save text image after execution.

• stat.S_IREAD: Read by owner.

• stat.S_IWRITE: Write by owner.

• stat.S_IEXEC: Execute by owner.

• stat.S_IRWXU: Read, write, and execute by owner.

• stat.S_IRUSR: Read by owner.

• stat.S_IWUSR: Write by owner.

• stat.S_IXUSR: Execute by owner.

• stat.S_IRWXG: Read, write, and execute by group.

• 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.

Note:This method has been introduced in Python 2.6

Syntax

Following is the syntax for lchmod() method:

os.lchmod(path, mode)

Parameters

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

TUTORIALS POINT

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!