how to print chinese word in my code.. using python

前端 未结 6 1262
别那么骄傲
别那么骄傲 2020-11-30 05:22

This is my code:

print \'哈哈\'.decode(\'gb2312\').encode(\'utf-8\')

...and it prints:

SyntaxError: Non-ASCII character \'\\x         


        
6条回答
  •  [愿得一人]
    2020-11-30 05:35

    You need to specify the encoding of the python source code file, here is the coding for utf-8. It goes at the top right underneath the path the the python interpreter.

    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    

    If you go to the url in the error message you can find more information about specifying the encoding of a python source file.

    Once you specify the encoding of the source file, you shouldn't have to decode the text.

提交回复
热议问题