[Python] Python cannot search Chinese string in file [duplicate]

Discussão em 'Python' iniciado por Stack, Março 28, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following text file named "test_data.txt":

    一行出去就係泳池,再行出啲就係沙灘。
    關


    And I have the following code to check if the wording "關" is included in the text file:

    data = open('test_data.txt', 'r')
    if '關' in data:
    print("yes")
    else:
    print("no")


    It prints:


    no
    ​

    How come? What did I miss?

    Continue reading...

Compartilhe esta Página