Open In App

Python | os.umask() method

Last Updated : 26 Jan, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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




# Python program to explain os.umask() method 
    
# importing os module 
import os
  
# mask
# 18 in decimal is
# equal to 0o022 in octal
mask = 18
  
# Set the current umask value
# and get the previous
# umask value
umask = os.umask(mask)
  
  
# Print the 
# current and previous 
# umask value
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




# Python program to explain os.umask() method 
    
# importing os module 
import os
  
# Octal value for umask
# octal value 0o777 is 
# 511 in decimal
mask = 0o777
  
# Set the current umask value
# and get the previous
# umask value
umask = os.umask(mask)
  
  
# Print the 
# current and previous 
# umask value
print("Current umask:", mask)
print("Previous umask:", umask) 


Output:

Current umask: 511
Previous umask: 18


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads