Python 2 and Python 3 dual development
Question: I'm just starting a new Python project, and ideally I'd like to offer Python 2
and 3 support from the start, with minimal developmental overhead. My question
is, what is the best way of doing this for brand new projects?

I have come across projects that run 2to3, or even 3to2, as part of their
installation script. This seems to be a very common way. However, there seems
to be several different ways of doing this. I also came across
[Distribute](http://packages.python.org/distribute/python3.html).

There is also the option of trying to write polyglot Python 2/Python 3 code.
Even though this seems like a horrible idea, I have noticed that I tend to
write code lately that is more idiomatic as Python 3 code, even though I still
run it as Python 2. I have a feeling this only helps my own transition when
the day finally arrives, and doesn't do much for offering or at least helping
dual support though.

Most of the projects offering dual support that I have seen added Python 3
support late, so I'm especially curious if there is a better way that is more
suited for new projects, where you have the benefit of a clean slate.

Thanks!

* * *

**Update:** Thanks everyone, here's a summary of the suggestions:

Polyglot (same source code files run on Python 2 and 3)

  * Use [six](http://packages.python.org/six/)
  * Especially viable if you don't require support for low versions of 2.*
  * No one suggested this, but use `from __future__ import ...` to give you Python 3 behavior with usually a modest Python 2.* requirement (for instance, Python 3-style division has been available since Python 2.2). This is especially applicable for brand new project, since it helps if you make this decision early on.
  * If your Python 3-specific code is very rare, you can check for `sys.version_info >= (3,)` and basically do what six does, but in an ad-hoc fashion.

Automatic conversion

  * Run [2to3](http://docs.python.org/library/2to3.html) or 3to2 automatically in `setup.py`
  * Use [Distribute](http://packages.python.org/distribute/python3.html) to do this for you (Distribute is a one-file project that can easily be included in your project so as to avoid another requirement, as mentioned [here](http://packages.python.org/distribute/using.html))
  * Rely on unit tests to make sure the conversion is sound

For videos about how to deal with Unicode and Time/date, check out [Paulo
Scardine's answer](http://stackoverflow.com/a/11372711/682907).


Answer: You should check out [six](http://packages.python.org/six/), a library that
provides a unified interface to various things that differ between Python 2
and 3.

