标题: Django python中 import cStringIO 错误提示 ModuleNotFoundError: No module named 'cStringIO' [打印本页] 作者: awagink 时间: 2020-8-27 09:17 标题: Django python中 import cStringIO 错误提示 ModuleNotFoundError: No module named 'cStringIO'
Django python中 import cStringIO 错误提示 ModuleNotFoundError: No module named 'cStringIO'
2.x写法:
import cStringIO
3.x写法:
from io import StringIO
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)