Count the number of Chinese character in one article

with open('Bmxxf.txt', encoding="utf8") as f:
    inp =
with open('lck.txt',encoding="utf8") as fi:
    inp1 =
with open('xsfh.txt', encoding="utf8") as fil:
    inp2 =
with open('yyd.txt', encoding="utf8") as filee:
    inp3 =
with open('ynj.txt', encoding="utf8") as fileee:
    inp4 =
print('Bmxxf has ' + str(inp.count('我')) + " 我 in it")

Hi, Can any one help me with this? I am trying to count the number of "我‘’ in the five articles(Bmxxf.txt, lck.txt, xsfh.txt, yyd.txt, ynj.txt). However after writing the first line to count the number of 我 in Bmxxf.txt. The program keeps showing me this:
File “”, line 16
SyntaxError: Non-UTF-8 code starting with ‘\xce’ in file on line 16, but no encoding declared; see for details

Does anyone know how to solve it?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

Please use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks are not single quotes.

I don’t think that you can just paste the character 我 into your code. Try using the character code instead.

I think it should handle the “我” character just fine.

Maybe the issue is in the text files. Check the encoding of the file (how it was saved) and maybe also make sure you didn’t inadvertently copy/paste any hidden characters into the text file.

You can also try setting the encoding as shown in the docs you linked to, and there is also a str.encode method.

(Not a python person BTW so…)