os.chmod() 的特殊字符路径

Special character path to os.chmod()

我有一个文件,其中包含一些带有特殊字符的路径。当我阅读并将其提供给 os.chmod 时,它没有找到路径:

fileNames.txt:

D:\DEV\spec_char\subtypes_and_built_in_macro ビルドイン Лестницы\teszt.xml

我的代码:

import os
from stat import S_IWRITE
with open('fileNames.txt', 'r') as f:
    read_data = f.readlines()   
    for data in read_data:
        os.chmod(data.strip(), S_IWRITE)

并得到以下错误:

    os.chmod(data.strip().decode('latin1'), S_IWRITE)
WindowsError: [Error 3] The system cannot find the path specified: u'D:\DEV\spec_char\subtypes_and_built_in_macro \xef\xbe\x8b\xef\xbe\x9e\xef\xbe\x99\xef\xbe\x84\xef\xbe\x9e\xef\xbd\xb2\xef\xbe\x9d \xd0\x9b\xd0\xb5\xd1\x81\xd1\x82\xd0\xbd\xd0\xb8\xd1\x86\xd1\x8b\teszt.xml'

我有一些只读文件,我想删除这些属性。

我使用 decode('utf-8') 现在它工作正常

 os.chmod(data.strip().decode('utf-8'), S_IWRITE)