Python: How to get StringIO.writelines to accept unicode string?

后端 未结 4 1409
予麋鹿
予麋鹿 2020-12-28 15:06

I\'m getting a

UnicodeEncodeError: \'ascii\' codec can\'t encode character u\'\\xa3\' in position 34: ordinal not in range(128)

on a strin

4条回答
  •  悲哀的现实
    2020-12-28 15:44

    Python 2.6 introduced the io module and you should consider using io.StringIO(), "An in-memory stream for unicode text."

    In older python versions this is not optimized (pure Python), in later versions this has been optimized to (fast) C code.

提交回复
热议问题