为什么当我尝试打印文件名数组时出现错误

时间:2019-11-17 19:17:11

标签: python operating-system python-os

def fetchExtension(folderDir):
    extensions = []
    arrayOfFiles = os.listdir(folderDir)

    #Fetches all the extension
    for file in arrayOfFiles:
        if "." in file:
            extension = file.split(".")
            extensions.append((file,extension[-1]))

    #Returns an array of extensions
    return extensions

fileExtension = fetchExtension(downloadDir)
print(fileExtension) 

我正在尝试从该文件夹中获取所有扩展名和文件名。然后返回一个文件名和扩展名的数组,但是当我尝试打印该数组时,我得到一个错误

return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 2152-2153: character maps to <undefined>

0 个答案:

没有答案