Python 3中的StringIO我正在使用Python3.2.1,我无法导入StringIO模块。我用io.StringIO它能用,但我不能用它numpy氏genfromtxt就像这样:x="1 3\n 4.5 8" numpy.genfromtxt(io.StringIO(x))我得到以下错误:TypeError: Can't convert 'bytes' object to str implicitly当我写import StringIO上面写着ImportError: No module named 'StringIO'
3 回答

慕少森
TA贡献2019条经验 获得超9个赞
当我编写导入StringIO时,它说没有这样的模块。
从…Python3.0的新特性是什么?:
这个
StringIO
和cStringIO
模块不见了。相反,导入io
模块与使用io.StringIO
或io.BytesIO
分别用于文本和数据。
.
修复Python 2代码的一种可能有用的方法也适用于Python 3(警告读取器):
try: from StringIO import StringIOexcept ImportError: from io import StringIO
注意:此示例可能与问题的主要问题切入,并且仅作为一般性地解决缺失问题时考虑的内容而包括在内。
StringIO
模块。对于更直接的解决方案,消息TypeError: Can't convert 'bytes' object to str implicitly

郎朗坤
TA贡献1921条经验 获得超9个赞
numpy.genfromtxt
numpy.genfromtxt(io.BytesIO(x.encode()))
添加回答
举报
0/150
提交
取消