首页 / PYTHON / 在Python中更改文件权限
在Python中更改文件权限
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了在Python中更改文件权限,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1801字,纯文字阅读大概需要3分钟。
内容图文
![在Python中更改文件权限](/upload/InfoBanner/zyjiaocheng/714/d13a7e6889a24a0ab43ba99e216c8600.jpg)
我正在尝试更改文件访问权限:
os.chmod(path, mode)
我想把它变为只读:
os.chmod(path, 0444)
有没有其他方法使文件只读?
解决方法:
os.chmod(path, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
The following flags can also be used in the mode argument of
os.chmod():
stat.S_ISUID
Set UID bit.
stat.S_ISGID
Set-group-ID bit. This bit has several special uses. For
a directory it indicates that BSD semantics is to be used for that
directory: files created there inherit their group ID from the
directory, not from the effective group ID of the creating process,
and directories created there will also get the S_ISGID bit set. For a
file that does not have the group execution bit (S_IXGRP) set, the
set-group-ID bit indicates mandatory file/record locking (see also
S_ENFMT).
stat.S_ISVTX
Sticky bit. When this bit is set on a directory it means
that a file in that directory can be renamed or deleted only by the
owner of the file, by the owner of the directory, or by a privileged
process.
stat.S_IRWXU
Mask for file owner permissions.
stat.S_IRUSR
Owner has read permission.
stat.S_IWUSR
Owner has write permission.
stat.S_IXUSR
Owner has execute permission.
stat.S_IRWXG
Mask for group permissions.
stat.S_IRGRP
Group has read permission.
stat.S_IWGRP
Group has write permission.
stat.S_IXGRP
Group has execute permission.
stat.S_IRWXO
Mask for permissions for others (not in group).
stat.S_IROTH
Others have read permission.
stat.S_IWOTH
Others have write permission.
stat.S_IXOTH
Others have execute permission.
stat.S_ENFMT
System V file locking enforcement. This flag is shared
with S_ISGID: file/record locking is enforced on files that do not
have the group execution bit (S_IXGRP) set.
stat.S_IREAD
Unix V7 synonym for S_IRUSR.
stat.S_IWRITE
Unix V7 synonym for S_IWUSR.
stat.S_IEXEC
Unix V7 synonym for S_IXUSR.
内容总结
以上是互联网集市为您收集整理的在Python中更改文件权限全部内容,希望文章能够帮你解决在Python中更改文件权限所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。