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

后端 未结 4 1377
予麋鹿
予麋鹿 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:42

    StringIO documentation:

    Unlike the memory files implemented by the StringIO module, those provided by [cStringIO] are not able to accept Unicode strings that cannot be encoded as plain ASCII strings.

    If possible, use StringIO instead of cStringIO.

提交回复
热议问题