Python 2 and Python 3 dual development -


i'm starting new python project, , ideally i'd offer python 2 , 3 support start, minimal developmental overhead. question is, best way of doing brand new projects?

i have come across projects run 2to3, or 3to2, part of installation script. seems common way. however, there seems several different ways of doing this. came across distribute.

there option of trying write polyglot python 2/python 3 code. though seems horrible idea, have noticed tend write code lately more idiomatic python 3 code, though still run python 2. have feeling helps own transition when day arrives, , doesn't offering or @ least helping dual support though.

most of projects offering dual support have seen added python 3 support late, i'm curious if there better way more suited new projects, have benefit of clean slate.

thanks!


update: everyone, here's summary of suggestions:

polyglot (same source code files run on python 2 , 3)

  • use six
  • especially viable if don't require support low versions of 2.*
  • no 1 suggested this, use from __future__ import ... give python 3 behavior modest python 2.* requirement (for instance, python 3-style division has been available since python 2.2). applicable brand new project, since helps if make decision on.
  • if python 3-specific code rare, can check sys.version_info >= (3,) , 6 does, in ad-hoc fashion.

automatic conversion

  • run 2to3 or 3to2 automatically in setup.py
  • use distribute (distribute one-file project can included in project avoid requirement, mentioned here)
  • rely on unit tests make sure conversion sound

for videos how deal unicode , time/date, check out paulo scardine's answer.

you should check out six, library provides unified interface various things differ between python 2 , 3.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -