Python documentation for os.removexattr — what does the '*' (star) argument mean?

那年仲夏 提交于 2020-01-21 12:05:21

问题


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 "<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.


回答1:


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.



来源:https://stackoverflow.com/questions/20810522/python-documentation-for-os-removexattr-what-does-the-star-argument-mea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!