work around for former CStringIO and String IO function in Python 3 Pdfinterp (Pdfminer)
<p>I am using the pdfminer tool to convert pdf to .csv (text) and one of the subcommands in the tool <code>pdfinterp.py</code> still uses the CStringIO and StringIO for string to string translation -</p>

<pre><code>import re
try:
    from CStringIO import StringIO 
except ImportError:
    from StringIO import StringIO
</code></pre>

<p>I am using Python 3 so I am aware of the need to change to io and io.StringIO. </p>

<p>How exactly should the above command be re-worded in <code>pdfinterp</code> to make it functional in Python 3.</p>

<p>you could extend your import block to make it compatible with all versions (Python 2.x or 3.x). Ugly because of all try/except blocks but would work</p>

<pre><code>try:
    from CStringIO import StringIO 
except ImportError:
    try:
        from StringIO import StringIO
    except ImportError:
        from io import StringIO
</code></pre>

<p>or (slightly better)</p>

<pre><code>import sys
if sys.version_info &lt; (3,)
   try:
       from CStringIO import StringIO 
   except ImportError:        
        from StringIO import StringIO
else:
     from io import StringIO
</code></pre>

<p>Be aware that python 3 has <code>BytesIO</code> too because binary data and text data is different now. So if <code>StringIO</code> is used to pass binary data it will fail.</p>

python c-strings pdfminer