Weird signs like ‘\x00s\x00v\x00e\x00n\x00l\x00o’ from reading a file

Do you also get weird signs like ‘\x00s\x00v\x00e\x00n\x00l\x00o’ when reading data from file?

It’s because UTF-16 encoding. You should decode it. Here’s the solution:

import codecs

filename = 'yourFileName.txt'

with codecs.open(filename, "r", "utf-16") as f:
data = f.read().splitlines()

print(data)
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x