我可以使用与StringIO相同的cStringIO吗? [英] Can I use cStringIO the same as StringIO?

查看:114
本文介绍了我可以使用与StringIO相同的cStringIO吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样做了:

import cStringIO.StringIO as StringIO

我知道我到处都在使用它.这样好吗 它与StringIO一样对待吗?

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

推荐答案

它们是不同的. cStringIO无法正确处理unicode字符.

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 "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)

这篇关于我可以使用与StringIO相同的cStringIO吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆