使用调用方法更改具有多个参数的文件属性

changing the file attribute with multiple args using call method

from subprocess import call

def change_attribute(filename,attrib):
try:
    call(["attrib ", attrib ,  filename])
except OSError as exception:
    raise exception

f1 = "D:\Tests\fileattrib\file1.txt"
att = ["+s","+h"]
#att = "+s" // this works fine 
#time.sleep(5)
change_attribute(f1,att)

我有一个函数 change_attribute() 可以更改文件属性。

在上面的脚本中,如果我将 'list' att 替换为 'string' 变量,效果很好。

但是如果我通过列表 att,它会抛出异常 "parameter format not correct"。

接受列表作为方法的参数需要进行哪些更改。请在python中将我视为新手。 任何帮助将不胜感激

call 需要一个字符串数组,而不是包含一个字符串的数组、一个字符串数组和另一个字符串。

你可以通过

解决这个问题
call(["attrib"] + attrib + ["filename"])