Easy Tutorial
❮ Python Func Number Atan2 Python Os Readlink ❯

Python3 os.lchmod() Method

Python3 OS File/Directory Methods


Overview

The os.lchmod() method is used to modify the permissions of a symbolic link.

This method is only supported on Unix systems.

Syntax

The syntax for the lchmod() method is as follows:

os.lchmod(path, mode)

Parameters

Return Value

This method does not return any value.

Example

The following example demonstrates the use of the lchmod() method:

#!/usr/bin/python3

import os, sys

# Open file
path = "/var/www/html/foo.txt"
fd = os.open(path, os.O_RDWR | os.O_CREAT)

# Close file
os.close(fd)

# Modify file permissions
# Set file to be executable by the group
os.lchmod(path, stat.S_IXGRP)

# Set file to be writable by others
os.lchmod("/tmp/foo.txt", stat.S_IWOTH)

print("Permissions modified successfully!!")

Executing the above program will output:

Permissions modified successfully!!

Python3 OS File/Directory Methods

❮ Python Func Number Atan2 Python Os Readlink ❯