十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
概述
os.access() 方法使用当前的uid/gid尝试访问路径。大部分操作使用有效的 uid/gid, 因此运行环境可以在 suid/sgid 环境尝试。
语法
access()方法语法格式如下:
os.access(path, mode);
参数
返回值
如果允许访问返回 True , 否则返回False。
实例
以下实例演示了 access() 方法的使用:
#!/usr/bin/python
# -*- coding: UTF-8 -*-import os, sys
# 假定 /tmp/foo.txt 文件存在,并有读写权限
ret = os.access("/tmp/foo.txt", os.F_OK)
print "F_OK - 返回值 %s"% retret = os.access("/tmp/foo.txt", os.R_OK)
print "R_OK - 返回值 %s"% retret = os.access("/tmp/foo.txt", os.W_OK)
print "W_OK - 返回值 %s"% retret = os.access("/tmp/foo.txt", os.X_OK)
print "X_OK - 返回值 %s"% ret
执行以上程序输出结果为:
F_OK - 返回值 True
R_OK - 返回值 True
W_OK - 返回值 True
X_OK - 返回值 False