How to use os.umask() in Python

后端 未结 4 1259
说谎
说谎 2020-12-31 07:34

I\'m trying to set a umask using the os module. Please note my normal umask set in my ~/.profile is umask 0027.

In a bash shell,

umask 0022
         


        
4条回答
  •  旧时难觅i
    2020-12-31 08:24

    Even though this would seem to be a straight system call, in this case it does seems to matter what Python version you are using:

    It appears that os.open handles the pre-existing umask differently in Python 2.x and Python 3.x, possibly because 2.x is closer to the OS and 3.x does a bit more abstraction.

    https://docs.python.org/2/library/os.html "The default mode is 0777 (octal), and the current umask value is first masked out."

    There is no similar statement in https://docs.python.org/3/library/os.html

提交回复
热议问题