Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top