When you learn that Python reads a file from a file and converts a string from a file into a list, you find that the file header has a \ufeff character.
This problem was encountered before, the same is the Internet search for a half-day to solve, at that time just to solve the problem is over, but today encountered the same problem, know there is such a solution, but how to do is not to remember. The Ancients cloud, good memory than bad writing, a bit right. Go to the chase.
A few conceptual things
Anscii:
STR). Like some other coding methods gb2312, GB18030, Big5 and UTF are the same, just coded differently.
A text file created under Windows with a text editor that, if saved in Unicode format such as UTF-8, adds a BOM ID to the file header (the first character). Specific removal methods look at the following code
1 #filename:example.py2 #Conding=utf-83 4f = open ("News.txt","R", encoding='Utf-8')5File =F.read ()6File_list = File.split (",")7 Print(file_list)8 9File_list2 = File.encode ('Utf-8'). Decode ('Utf-8-sig')Ten Print(FILE_LIST2) One A - #printing results are as follows -['\ufeff Xinhua News Agency, Beijing, February 8, February 8'] theBEIJING, February 8 (Xinhua) February 8
Do not understand a lot, and slowly accumulate.
Python string to list appears \ufeff workaround