all Python 3osfunction
os.umask
os — process
Set the file-creation mode mask and return the previous value.
Syntax
os.umask(mask)
There is no way to read the mask without changing it: the usual idiom is old = os.umask(0); os.umask(old). The mask is process-wide, and between the two calls another thread may create a file with a zero mask. The mask removes permissions rather than setting them: with umask 022 a file created with 0o666 ends up 0o644.
Examples
import os
old = os.umask(0o022)
os.umask(old)
print(isinstance(old, int)) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy