Python read file, Python read 1 becomes \ufeff1

Source: Internet
Author: User

' \ufeff1 '

1movies={}2Fm=open (self.path+'/movie.txt', encoding='Utf-8')3W2=open ('./data/1.txt','a')4          forLineinchFM:5(Movie_id,title) =line.strip (). Split ("||")6             #print (Type (movie_id))7             Print(MOVIE_ID,'-----')8             #Int (movie_id)9             #Int (movie_id)Tenmovies[movie_id]=title Ones=str (Movies) A W2.writelines (s) - w2.close () -         Print(Movies)

Reason:

There is a problem with the original file, workaround:

How to solve?
Turn the file into a BOM-free UTF-8 and it's OK.
General compilers have the ability to reformat: I'm using notepad++.

Ctrl +s Save, run or possibly report the same error, here is another operation: Save as + replace

Python read file, Python read 1 becomes \ufeff1

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.