[Biopython-dev] Python 2 and 3 migration thoughts

Eric Talevich eric.talevich at gmail.com
Mon Oct 14 20:34:00 UTC 2013


On Mon, Oct 14, 2013 at 8:00 AM, Peter Cock <p.j.a.cock at googlemail.com>wrote:

> Hello all,
>
> Despite a nasty cold, I've made further progress over the
> weekend. Switching to assuming Python 3 style dictionaries
> is a single biggest step forward - and as long as we have
> good test coverage I think this is low risk. I think a dual
> code base without needing 2to3 may be attainable for
> the next Biopython release.


Nice :)


> [...] something far more common is
> StringIO, which also crops up in our doctests. e.g.
>
> Python 2 only:
>
> >>> from StringIO import StringIO
>
> Both 2 and 3:
>
> >>> try:
> ...     from StringIO import StringIO # Python 2
> ... except ImportError:
> ...     from io import StringIO # Python 3
> ...
>

For the case of StringIO and BytesIO, the top-level io module was added in
Python 2.6:
http://docs.python.org/2/library/io.html

In Py2.6, the implementation of io.StringIO is slow, and io.BytesIO not
meaningfully different from io.StringIO, but both should be fine for
doctests.

-Eric



More information about the Biopython-dev mailing list