我知道如何使用以下代码实现chmod u + w:
st = os.stat(dest_file)
os.chmod(dest_file, st.st_mode | stat.S_IWUSR)
Run Code Online (Sandbox Code Playgroud)
但是怎么样?
st = os.stat(dest_file)
os.chmod(dest_file, st.st_mode & ~stat.S_IWUSR)
Run Code Online (Sandbox Code Playgroud)
说明:~是按位NOT运算符,因此按位AND将~stat.S_IWUSR清除该标志st.st_mode.
用虚数值来说明:
stat.S_IWUSR 00001000
~stat.S_IWUSR 11110111
s.st_mode 00101001
s.st_mode & ~stat.S_IWUSR 00100001
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
404 次 |
| 最近记录: |