Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.4 : cStringIO vs. StringIO

QUESTION

I am returning an ImportError: No module named 'cStringIO'. Unfortunately cStringIO doesn't exist anymore and I need to use StringIO as a replacement. How can I do this?

import edgar
import ftplib
from io import StringIO 

ftp = ftplib.FTP(edgar.FTP_ADDR)
ftp.login()
try:
   edgar.download_all(ftp, "/tmp")
except Exception as e:
   print(e)
finally:
   ftp.close()

OUTPUT

Traceback (most recent call last):
File "/usr/local/lib/ana/lib/python3.4/site-         packages/edgar/downloader.py", line 5, in <module>
from cStringIO import StringIO
ImportError: No module named 'cStringIO'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/aranjohn/PycharmProjects/edgar/secEd.py", line 1, in     <module>
import edgar
File "/usr/local/lib/ana/lib/python3.4/site-  packages/edgar/__init__.py", line 1, in <module>
from .downloader import FTP_ADDR, file_list, download, download_all
File "/usr/local/lib/ana/lib/python3.4/site-  packages/edgar/downloader.py", line 7, in <module>
from StringIO import StringIO
ImportError: No module named 'StringIO'

Process finished with exit code 1
like image 383
Aran Freel Avatar asked May 21 '15 15:05

Aran Freel


1 Answers

StringIO no longer exists in 3.x. Use either io.StringIO for text or io.BytesIO for bytes.

like image 88
Ignacio Vazquez-Abrams Avatar answered Sep 19 '22 16:09

Ignacio Vazquez-Abrams