OS File 中的 os.fchmod(fd, mode)函数

首页 / Python2入门教程 / OS File 中的 os.fchmod(fd, mode)函数

Python方法fchmod()将fd给定的文件模式更改为数值模式。

os.fchmod(fd, mode) - 语法

os.fchmod(fd, mode);
  • fd        -  这是将为其设置模式的文件描述符。

  • mode  -  这可能采用上面提到的值之一或它们的按位或组合。

os.fchmod(fd, mode) - 示例

以下示例显示了fchmod()方法-的用法

#!/usr/bin/python

import os, sys, stat

# Now open a file "/tmp/foo.txt"
fd=os.open( "/tmp", os.O_RDONLY )

# Set a file execute by the group.

os.fchmod( fd, stat.S_IXGRP)

# Set a file write by others.
os.fchmod(fd, stat.S_IWOTH)

print "Changed mode successfully!!"

# Close opened file.
os.close( fd )

当无涯教程运行上面的程序时,它产生以下输出-

链接:https://www.learnfk.comhttps://www.learnfk.com/python/os-fchmod.html

来源:LearnFk无涯教程网

Changed mode successfully!!

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Nginx核心知识150讲 -〔陶辉〕

.NET Core开发实战 -〔肖伟宇〕

Web安全攻防实战 -〔王昊天〕

重学线性代数 -〔朱维刚〕

说透低代码 -〔陈旭〕

自动化测试高手课 -〔柳胜〕

零基础学Python(2023版) -〔尹会生〕

AI绘画核心技术与实战 -〔南柯〕

云时代的JVM原理与实战 -〔康杨〕

好记忆不如烂笔头。留下您的足迹吧 :)