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()方法-的用法

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

来源:LearnFk无涯教程网

#!/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 )

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

无涯教程网

Changed mode successfully!!

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

技术教程推荐

朱赟的技术管理课 -〔朱赟〕

白话法律42讲 -〔周甲徳〕

程序员的数学基础课 -〔黄申〕

软件工程之美 -〔宝玉〕

透视HTTP协议 -〔罗剑锋(Chrono)〕

陶辉的网络协议集训班02期 -〔陶辉〕

业务开发算法50讲 -〔黄清昊〕

运维监控系统实战笔记 -〔秦晓辉〕

LangChain 实战课 -〔黄佳〕

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