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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • ADB安装卸载应用[通俗易懂]

    ADB安装卸载应用[通俗易懂]一、目的使用adb快速安装apk手机app使用adb卸载app(卸载手机自带应用,root下)二、操作2.1adb安装apk手机USB连接电脑(连接成功进入adb)执行adbinstall-r<apk绝对路径>只需要将文件拉近cmd窗口中便会自动解析路径(最好将apk放到c盘)手机中确认安装即可…

    2022年5月13日
  • Git指令大全[通俗易懂]

    Git指令大全[通俗易懂]转自:https://mp.weixin.qq.com/s/sF-cx2ss4haO74K55Sjf9g配置首先是配置帐号信息ssh-Tgit@github.com#登陆github修改项目中的个人信息gitconfig–globaluser.name“githelper”gitconfig–globaluser.emailgithelper@gmail.c

    2022年5月7日
  • RT-Thread进阶笔记之FinSH组件「建议收藏」

    RT-Thread进阶笔记之FinSH组件「建议收藏」1

    2022年5月21日
  • 两款免费、好用的数据库连接工具

    一、NavicateNavicat是一套快速、可靠的数据库管理工具,专为简化数据库的管理及降低系统管理成本而设。它的设计符合数据库管理员、开发人员及中小企业的需要。Navicat是以直觉化的图形用户界面而建的,让你可以以安全并且简单的方式创建、组织、访问并共用信息。1、安装步骤(1)解压navicat_premium12文件,得到安装文件和破解文件。(2)双击navicat12024_premium_cs_x64.exe安装文件,根据点击下一步安装完成,记住安装目录,安装完成后先不

    2022年4月4日
  • [MicroPython]TurniBit开发板DIY自动窗帘模拟系统

    [MicroPython]TurniBit开发板DIY自动窗帘模拟系统一、准备工作üTurnipBit开发板一块ü下载数据线一条ü微型步进电机(28BYJ-48)一个ü步进电机驱动板(ULN2003APG)一块ü光敏传感器一个üTurnipBit扩展板一块ü接入网络的电脑一台ü在线可视化编程器<http://turnipbit.com/PythonEditor/edit…

    2022年6月23日
  • 【豆瓣达人总结】做爱做的事,看有趣的人

    【豆瓣达人总结】做爱做的事,看有趣的人惊雀http://www.douban.com/people/4917689/有想法很特别的一位大哥,从另一个角度告诉你什么叫做“人不可貌相”,有位友邻说得好:之所以觉得惊先生特别是因为先生是为数不多思考爱情的帅哥~@东窗未白keledollhttp://www.douban.com/people/keledoll/热血科学心理学女青年,今天才发现她有豆瓣页面。搜索kele

    2022年9月28日

发表回复

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

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