Unicode (UTF-8) reading and writing to files in Python

前端 未结 14 1229
谎友^
谎友^ 2020-11-22 17:10

I\'m having some brain failure in understanding reading and writing text to a file (Python 2.4).

# The string, which has an a-acute in it.
ss = u\'Capit\\xe1         


        
14条回答
  •  庸人自扰
    2020-11-22 17:28

    To read in an Unicode string and then send to HTML, I did this:

    fileline.decode("utf-8").encode('ascii', 'xmlcharrefreplace')
    

    Useful for python powered http servers.

提交回复
热议问题