python 3.x ImportError: No module named 'cStringIO'

﹥>﹥吖頭↗ 提交于 2019-11-26 07:40:40

问题


How do I solve an ImportError: No module named \'cStringIO\' under Python 3.x?


回答1:


From Python 3.0 changelog;

The StringIO and cStringIO modules are gone. Instead, import the io module and use io.StringIO or io.BytesIO for text and data respectively.

From the Python 3 email documentation it can be seen that io.StringIO should be used instead:

from io import StringIO
from email.generator import Generator
fp = StringIO()
g = Generator(fp, mangle_from_=True, maxheaderlen=60)
g.flatten(msg)
text = fp.getvalue()

Reference: https://docs.python.org/3.4/library/io.html




回答2:


I had the same issue because my file was called email.py. I renamed the file and the issue disappeared.



来源:https://stackoverflow.com/questions/28200366/python-3-x-importerror-no-module-named-cstringio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!