分割时,特殊字符不正确显示 [英] Special caracters don't display correctly when splitting

查看:171
本文介绍了分割时,特殊字符不正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在文本文件中阅读一行时,如下所示:

When I'm reading a line in a text file, like this one below :

présenté alloué ééé ààà tué

并尝试在终端中打印,它显示正确。但是当我用空格作为分隔符应用分割时,它显示:

And try to print it in the terminal, it displays correctly. But when I apply a split with a space as separator, it displays this :

['pr\xc3\xa9sent\xc3\xa9', 'allou\xc3\xa9', '\xc3\xa9\xc3\xa9\xc3\xa9', '\xc3\xa0\xc3\xa0\xc3\xa0', 'tu\xc3\xa9\n']

我只是用这个来阅读文本文件:

I just use this to read the text file :

f = open("test.txt")
l = f.readline()
f.close()
print l.split(" ")

有人可以帮助我吗?

推荐答案

打印列表与打印其元素不一样

Printing the list is not the same as printing its elements

s = "présenté alloué ééé ààà tué"
print s.split(" ")
for x in s.split(" "):
    print x

输出:

['pr\xc3\xa9sent\xc3\xa9', 'allou\xc3\xa9', '\xc3\xa9\xc3\xa9\xc3\xa9', '\xc3\xa0\xc3\xa0\xc3\xa0', 'tu\xc3\xa9']
présenté
alloué
ééé
ààà
tué

这篇关于分割时,特殊字符不正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆