Re: read a file and remove Mojibake chars

2016-04-07 Thread Random832
On Thu, Apr 7, 2016, at 04:47, Daiyue Weng wrote: > Hi, when I read a file, the file string contains Mojibake chars at the > beginning, the code is like, > > file_str = open(file_path, 'r', encoding='utf-8').read() > print(repr(open(file_path, 'r', encoding='utf-8').read()) > > part of the string

Re: read a file and remove Mojibake chars

2016-04-07 Thread Chris Angelico
On Thu, Apr 7, 2016 at 6:47 PM, Daiyue Weng wrote: > Hi, when I read a file, the file string contains Mojibake chars at the > beginning, the code is like, > > file_str = open(file_path, 'r', encoding='utf-8').read() > print(repr(open(file_path, 'r', encoding='utf-8').read()) > > part of the string

Re: read a file and remove Mojibake chars

2016-04-07 Thread Peter Otten
Daiyue Weng wrote: > Hi, when I read a file, the file string contains Mojibake chars at the > beginning, the code is like, > > file_str = open(file_path, 'r', encoding='utf-8').read() > print(repr(open(file_path, 'r', encoding='utf-8').read()) > > part of the string (been printing) containing Mo

Re: read a file and remove Mojibake chars

2016-04-07 Thread Ben Finney
Daiyue Weng writes: > Hi, when I read a file, the file string contains Mojibake chars at the > beginning You are explicitly setting an encoding to read the file; that is good, since Python should not guess the input encoding. The reason it's good is because the issue, of knowing the correct tex

read a file and remove Mojibake chars

2016-04-07 Thread Daiyue Weng
Hi, when I read a file, the file string contains Mojibake chars at the beginning, the code is like, file_str = open(file_path, 'r', encoding='utf-8').read() print(repr(open(file_path, 'r', encoding='utf-8').read()) part of the string (been printing) containing Mojibake chars is like, '锘縶\n "na