stringio – python 3.x ImportError: No module named cStringIO
stringio – python 3.x ImportError: No module named cStringIO
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()
I had the same issue because my file was called email.py. I renamed the file and the issue disappeared.
stringio – python 3.x ImportError: No module named cStringIO
I had the issue because my directory was called email
. I renamed the directory to emails
and the issue was gone.
Related Posts
- Is there a package manager for Java like easy_install for Python?
- Call Python function from JavaScript code
- Web-scraping JavaScript page with Python
- Understanding the Python %g in string formatting, achieving Java String.format behavior
- Postpone code for later execution in python (like setTimeout in javascript)
- Confused, are languages like python, ruby single threaded? unlike say java? (for web apps)
- Conversion from JavaScript to Python code?