python的os库的remove可以删除只带有只读属性的_os.removexattr的Python文档-'*'(星号)参数是什么意思?...

My first question, please be gentle. I searched but could not find an answer here or elsewhere.

Note that this question does not apply to unpacking of arguments like *args.

In the python 3.3 documentation for os.removexattr the following is stated:

os.removexattr(path, attribute, *, follow_symlinks=True)

Removes the extended filesystem attribute attribute from path.

attribute should be bytes or str. If it is a string, it is encoded

with the filesystem encoding.

This function can support specifying a file descriptor and not

following symlinks.

Note that the third argument is a star: *

I assumed that this means "specify one attribute or several attributes separated by comma",

but when trying to do that, I get an exception:

import os

os.removexattr('M7-AAE-01.jpg', 'user.camera_brand', 'user.camera_model')

Traceback (most recent call last):

File "", line 1, in

TypeError: Function takes at most 2 positional arguments (3 given)

I also tried to supply a list of arguments, but that did not work either.

What exactly does the star argument mean in this case?

Thank you.

解决方案

The single asterisk * just means that it is forcing you to use named arguments. In this case if you want to pass a value for follow_symlinks, you have to pass the argument name.

The idea is you don't having to read function calls like foo(True, False, False) and not know what those values are doing.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值