Can I use cStringIO the same as StringIO?

后端 未结 2 1432
深忆病人
深忆病人 2021-02-07 06:59

I did this:

import cStringIO.StringIO as StringIO

And I realize I\'ve been using it everywhere. Is that fine? Is it treated the same as String

2条回答
  •  庸人自扰
    2021-02-07 07:38

    They are not the same. cStringIO doesn't correctly handle unicode characters.

    >>> StringIO.StringIO().write(u'\u0080')
    
    >>> cStringIO.StringIO().write(u'\u0080')
    Traceback (most recent call last):
      File "", line 1, in 
    UnicodeEncodeError: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
    

提交回复
热议问题