Python, how to print Japanese, Korean, Chinese strings

前端 未结 5 1927
情书的邮戳
情书的邮戳 2021-01-13 12:55

In Python, for Japanese, Chinese, and Korean,Python can not print the correct strings, for example hello in Japanese, Korean and Chinese are:

こん         


        
5条回答
  •  我在风中等你
    2021-01-13 13:30

    My python version 2.7.11 and operating system is Mac OSX,I write

    こんにちは
    안녕하세요
    你好
    

    to test.txt. My program is :

    # -*-coding:utf-8-*-
    
    import json
    
    
    if __name__ == '__main__':
        f = open("./test.txt", "r")
        a = f.readlines()
        print json.dumps(a, ensure_ascii=False)
        f.close()
    

    run the program, result:

    ["こんにちは\n", "안녕하세요\n", "你好"]
    

提交回复
热议问题