读入文件,也遇到了类似于下面帖子中的这个问题,查了些decode的方法都没有解决
https://stackoverflow.com/questions/4735566/python-unicode-problem
最终的解决方法: “utf-16”
data = open(...).read()
data.decode("utf-16")
附上自己的代码(含文件的读取):
filename1 = "D:\Fiddler Sessions\VerifyRequset.txt"
with open(filename1, 'rb')as f:
data = f.read()
data = data.decode("utf-16")
print(data)
摘:
I am trying to decode a string I took from file:
file = open ("./Downloads/lamp-post.csv", 'r')
data = file.readlines()
data[0]
'\xff\xfeK\x00e\x00y\x00w\x00o\x00r\x00d\x00\t\x00C\x00o\x00m\x00p\x00e\x00t\x00i\x00t\x00