6

最初の質問です、お手柔らかにお願いします。検索しましたが、ここでも他の場所でも答えが見つかりませんでした。

この質問は、*args のような引数のアンパックには適用されないことに注意してください。

os.removexattrの python 3.3 ドキュメントには、次のように記載されています。

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.

3 番目の引数がアスタリスクであることに注意してください: *

これは「1 つの属性またはコンマで区切られた複数の属性を指定する」ことを意味すると想定しましたが、それを実行しようとすると例外が発生します。

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)

また、引数のリストを提供しようとしましたが、それもうまくいきませんでした。

この場合、スター引数は正確には何を意味するのでしょうか? ありがとうございました。

4

1 に答える 1

5

単一のアスタリスク*は、名前付き引数の使用を強制していることを意味します。この場合、 の値を渡したい場合はfollow_symlinks、引数名を渡す必要があります。

アイデアは、関数呼び出しを読む必要がなくfoo(True, False, False)、それらの値が何をしているのかわからないということです。

于 2013-12-28T03:02:16.780 に答える