python目录名称无效怎么处理_python-如何通过名称更改目录的用户和组权限?

由于shutil版本支持group是可选的,因此我将代码复制并粘贴到我的Python2项目中。

[https://hg.python.org/cpython/file/tip/Lib/shutil.py#l1010]

def chown(path, user=None, group=None):

"""Change owner user and group of the given path.

user and group can be the uid/gid or the user/group names, and in that case,

they are converted to their respective uid/gid.

"""

if user is None and group is None:

raise ValueError("user and/or group must be set")

_user = user

_group = group

# -1 means don't change it

if user is None:

_user = -1

# user can either be an int (the uid) or a string (the system username)

elif isinstance(user, basestring):

_user = _get_uid(user)

if _user is None:

raise LookupError("no such user: {!r}".format(user))

if group is None:

_group = -1

elif not isinstance(group, int):

_group = _get_gid(group)

if _group is None:

raise LookupError("no such group: {!r}".format(group))

os.chown(path, _user, _group)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值