Python os.lchown() 方法
python os.lchown() 方法
os.lchown() 方法用于更改文件所有者,類(lèi)似 chown,但是不追蹤鏈接。
只支持在 unix 下使用。
語(yǔ)法
lchown()方法語(yǔ)法格式如下:
os.lchown(path, uid, gid)
參數(shù)
- path -- 設(shè)置權(quán)限的文件路徑
- uid -- 所屬用戶(hù) id
- gid -- 所屬用戶(hù)組 id
返回值
該方法沒(méi)有返回值。
實(shí)例
以下實(shí)例演示了 lchown() 方法的使用:
#!/usr/bin/python # -*- coding: utf-8 -*- import os, sys # 打開(kāi)文件 path = "/var/www/html/foo.txt" fd = os.open( path, os.o_rdwr|os.o_creat ) # 關(guān)閉打開(kāi)的文件 os.close( fd ) # 修改文件權(quán)限 # 設(shè)置文件所屬用戶(hù) id os.lchown( path, 500, -1) # 設(shè)置文件所屬用戶(hù)組 id os.lchown( path, -1, 500) print "修改權(quán)限成功!!"
執(zhí)行以上程序輸出結(jié)果為:
修改權(quán)限成功!!
相關(guān)文章
- Python 變量類(lèi)型
- Python 函數(shù)
- Python 正則表達(dá)式
- Python 數(shù)組
- Python 列表
- Python 集合
- Python 節(jié)點(diǎn)
- Python Deque
- Python 高級(jí)鏈表
- Python 算法設(shè)計(jì)
- Python 回溯
- Python 排序算法
- Python 大O符號(hào)
- Python 攤銷(xiāo)分析
- Python 算法理由
- Python3 簡(jiǎn)介
- Python3 解釋器
- Python3 字典(Dictionary)
- Python3 模塊
- Python3 錯(cuò)誤和異常