use*_*335 6 python operating-system file-attributes
我的第一个问题,请温柔。我搜索但无法在此处或其他地方找到答案。
请注意,此问题不适用于解包 *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.
Run Code Online (Sandbox Code Playgroud)
请注意,第三个参数是一个星号:*
我认为这意味着“指定一个或多个用逗号分隔的属性”,但是在尝试执行此操作时,出现异常:
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)
Run Code Online (Sandbox Code Playgroud)
我也试图提供一个参数列表,但这也不起作用。
在这种情况下,star 参数究竟意味着什么?谢谢你。
单个星号*仅表示它迫使您使用命名参数。在这种情况下,如果要为 传递值follow_symlinks,则必须传递参数名称。
这个想法是你不必阅读函数调用foo(True, False, False),也不知道这些值在做什么。