本文介绍了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 文档——'*'(星号)参数是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 18:10