List files with UTF-8 characters in the name in Python ftplib

删除回忆录丶 提交于 2020-11-29 03:10:50

问题


I need to mirror files from an FTP server to a local machine, but some files/directories have special characters on it, e.g:

print(ftp.nlst())
>>{'Mariana', 'Marina', 'MartÃ\xadn', 'MatÃ\xadas'}

回答1:


Assuming the filenames are in UTF-8 encoding, in Python 3, this should do:

ftp.encoding = "UTF-8"
print(ftp.nlst())


来源:https://stackoverflow.com/questions/53091871/list-files-with-utf-8-characters-in-the-name-in-python-ftplib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!