Python removes zero-width characters ZWNBSP

When we read a txt file, sometimes there will be an encoding problem, that is, there is an extra zero-width character in a line for no reasonZero-width character , as shown below:

Insert image description here

I found that this problem can be solved in python3 as follows:

open(file_path, mode='r', encoding='UTF-8-sig')

Just open the file in this way, provided that the python interpreter is python3

Reference documentation is here

Guess you like

Origin blog.csdn.net/qq_41841073/article/details/121933925#comments_29534439