Python | os.umask() method
Last Updated :
26 Jan, 2022
OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.
os.umask()
method in Python is used to set the current numeric umask value and get the previous umask value.
umask stands for user file-creation mode mask. This is used to determine the file permission for newly created files or directories.
Syntax: os.umask(mask)
Parameter:
mask: An integer value denoting a valid umask value.
Return Type: This method sets the current umask value and returns an integer value which represents the previous umask value.
Code #1: Use of os.umask() method
import os
mask = 18
umask = os.umask(mask)
print ( "Current umask:" , mask)
print ( "Previous umask:" , umask)
|
Output:
Current umask: 18
Previous umask: 54
Code #2: Passing an octal value as parameter in os.umask() method
import os
mask = 0o777
umask = os.umask(mask)
print ( "Current umask:" , mask)
print ( "Previous umask:" , umask)
|
Output:
Current umask: 511
Previous umask: 18
Share your thoughts in the comments
Please Login to comment...