Python documentation for os.removexattr -- what does the #39;*#39; (star) argument mean?(os.removexattr 的 Python 文档——*(星号)参数是什么意思?)
问题描述
我的第一个问题,请温柔一点.我搜索但在这里或其他地方找不到答案.
My first question, please be gentle. I searched but could not find an answer here or elsewhere.
请注意,此问题不适用于 *args 等参数的解包.
Note that this question does not apply to unpacking of arguments like *args.
在 os.removexattr 声明如下:
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 "<stdin>", line 1, in <module>
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.
推荐答案
单个星号 * 仅表示它强制您使用命名参数.在这种情况下,如果你想为 follow_symlinks 传递一个值,你必须传递参数名称.
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.
这个想法是您不必阅读像 foo(True, False, False) 这样的函数调用并且不知道这些值在做什么.
The idea is you don't having to read function calls like foo(True, False, False) and not know what those values are doing.
这篇关于os.removexattr 的 Python 文档——'*'(星号)参数是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:os.removexattr 的 Python 文档——'*'(星号)参数
- 分析异常:路径不存在:dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; 2022-01-01
- python-m http.server 443--使用SSL? 2022-01-01
- python check_output 失败,退出状态为 1,但 Popen 适用于相同的命令 2022-01-01
- 沿轴计算直方图 2022-01-01
- 如何在 Python 的元组列表中对每个元组中的第一个值求和? 2022-01-01
- 如何将一个类的函数分成多个文件? 2022-01-01
- 如何在 python3 中将 OrderedDict 转换为常规字典 2022-01-01
- pytorch 中的自适应池是如何工作的? 2022-07-12
- padding='same' 转换为 PyTorch padding=# 2022-01-01
- 使用Heroku上托管的Selenium登录Instagram时,找不到元素';用户名'; 2022-01-01
