python chmod_Python os.chmod用法及代码示例

python chmod_Python os.chmod用法及代码示例Python中的os.chmod()方法用于将路径模式更改为数字模式。用法:os.chmod(path,mode)参数:path-pathnameofthefileordirectorypathmode-modemaytakeoneofthefollowingvalues:stat.S_ISUID:SetuserIDonexecutionstat.S…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

Python中的os.chmod()方法用于将路径模式更改为数字模式。

用法:

os.chmod(path, mode)

参数:

path – path name of the file or directory path

mode – modemay take one of the following values:

stat.S_ISUID : Set user ID on execution

stat.S_ISGID : Set group ID on execution

stat.S_ENFMT : Record locking enforced

stat.S_ISVTX : Save text image after execution

stat.S_IREAD : Read by owner.

stat.S_IWRITE : Write by owner.

stat.S_IEXEC : Execute by owner.

stat.S_IRWXU : Read, write, and execute by owner

stat.S_IRUSR : Read by owner

stat.S_IWUSR : Write by owner.

stat.S_IXUSR : Execute by owner.

stat.S_IRWXG : Read, write, and execute by group

stat.S_IRGRP : Read by group

stat.S_IWGRP : Write by group

stat.S_IXGRP :Execute by group

stat.S_IRWXO : Read, write, and execute by others.

stat.S_IROTH : Read by others

stat.S_IWOTH :Write by others

stat.S_IXOTH : Execute by others

代码1:

# Python program to explain os.chmod() method

# importing necessary libraries

import os, sys, stat

# Set given file read by the owner.

os.chmod(“/Geeks/gfg.txt”, stat.S_IREAD)

print(“File can be read only by owner.”)

# Set given file read by others.

os.chmod(“/Geeks/gfg.txt”, stat.S_IROTH)

print(“File access changed, can be read by others now.”)

输出:

File can be read only by owner.

File access changed, can be read by others now.

代码2:

# Python program to explain os.chmod() method

# importing necessary libraries

import os, sys, stat

# Set given file written by the owner.

os.chmod(“/Geeks/gfg.txt”, stat.S_IWRITE)

# Set given file executed by the owner.

os.chmod(“/Geeks/gfg.txt”, stat.S_IXUSR)

print(“File can be written and executed only by owner.”)

输出:

File can be written and executed only by owner.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/179869.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • SQL查询–约束「建议收藏」

    SQL查询–约束「建议收藏」在慕课网上学习时记的关于oracle中约束概念的基础笔记,当初一直对约束的概念不清不楚的,所以找了些资料来看约束是数据库用来确保数据满足业务规则的手段约束的作用:定义规则、确保完整性1.非空约束

    2022年7月2日
    21
  • 正则表达式:匹配不包含某些字符和不包含某些字符串的写法「建议收藏」

    正则表达式:匹配不包含某些字符和不包含某些字符串的写法「建议收藏」不包含某些字符:不包含某些字符串:当然下面不包含字符串可以演变为不包含字符使用,看你喜欢使用。

    2022年7月2日
    26
  • layoutSubviews的使用

    layoutSubviews的使用-(void)layoutSubviews{ }layoutSubviews是对subviews的重新布局以下情况会被调用1.直接调用layoutSubviews.如:[selflayoutSubviews];2.用addSubview添加视图时会触发3.滚动UIScrollView时会触发4.旋转屏幕的时候会触发父视图的layoutSu

    2022年7月15日
    14
  • seekg()/seekp()与tellg()/tellp()的用法详解

    seekg()/seekp()与tellg()/tellp()的用法详解对输入流操作:seekg()与tellg()对输出流操作:seekp()与tellp()下面以输入流函数为例介绍用法:seekg()是对输入文件定位,它有两个参数:第一个参数是偏移量,第二个参数是基地址。对于第一个参数,可以是正负数值,正的表示向后偏移,负的表示向前偏移。而第二个参数可以是:ios::beg:表示输入流的开始位置ios::cur:表示输入流的当前位置io

    2022年6月9日
    77
  • linux查看防火墙状态_Linux关闭防火墙

    linux查看防火墙状态_Linux关闭防火墙service iptablesstatus;systemctlstatus firewalld;关闭防火墙命令:systemctl stop firewalld.service开启防火墙:systemctl startfirewalld.service关闭开机自启动:systemctl disable firewalld.service开启开机启动:syste…

    2022年4月19日
    54
  • wsus无法同步计算机,Windows Update无法与WSUS同步,8024401c「建议收藏」

    wsus无法同步计算机,Windows Update无法与WSUS同步,8024401c「建议收藏」Hello,WSUS环境是windowsserver2016,客户端有server16和win101809,windows10可以正常与WSUS同步,其中一台windowsserver2016始终无法与wsus同步,查看该服务器的windowsupdatelog,得到以下信息===================================2019/09/1811:32:13.6…

    2022年6月14日
    46

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号