gpt4 book ai didi

python - 在 Python ftplib 中列出名称中包含 UTF-8 字符的文件

转载 作者:行者123 更新时间:2023-12-01 08:51:25 25 4
gpt4 key购买 nike

我需要将文件从 FTP 服务器镜像到本地计算机,但某些文件/目录上有特殊字符,例如:

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

最佳答案

假设文件名采用 UTF-8 编码,在 Python 3 中,应该这样做:

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

关于python - 在 Python ftplib 中列出名称中包含 UTF-8 字符的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53091871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com