UTF-8 problem in python when reading chars

后端 未结 5 1668
温柔的废话
温柔的废话 2021-02-06 06:58

I\'m using Python 2.5. What is going on here? What have I misunderstood? How can I fix it?

in.txt:

Stäckövérfløw

code.py

5条回答
  •  忘了有多久
    2021-02-06 07:36

    One may want to just use

    f = open('in.txt','r')
    for line in f:
        print line
        for i in line.decode('utf-8'):
            print i,
    f.close()
    

提交回复
热议问题