UTF-8 problem in python when reading chars

后端 未结 5 1715
温柔的废话
温柔的废话 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:22

    print c,
    

    Adds a "blank charrecter" and breaks correct utf-8 sequences into incorrect one. So this would not work unless you write a signle byte to output

    sys.stdout.write(i)
    

提交回复
热议问题