Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6277fa4

Browse files
committed
Update the porting HOWTO to be a little less harsh on using 2to3.
Patch reviewed by Raymond Hettinger, permission from Georg Brandl to commit during an RC.
1 parent 8f0ae9a commit 6277fa4

1 file changed

Lines changed: 20 additions & 23 deletions

File tree

Doc/howto/pyporting.rst

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,18 @@ If your project is brand-new or does not have a large codebase, then you may
3131
want to consider writing/porting :ref:`all of your code for Python 3
3232
and use 3to2 <use_3to2>` to port your code for Python 2.
3333

34-
If your project has a pre-existing Python 2 codebase and you would like Python
35-
3 support to start off a new branch or version of your project, then you will
36-
most likely want to :ref:`port using 2to3 <use_2to3>`. This will allow you to
37-
port your Python 2 code to Python 3 in a semi-automated fashion and begin to
38-
maintain it separately from your Python 2 code. This approach can also work if
39-
your codebase is small and/or simple enough for the translation to occur
40-
quickly.
41-
42-
Finally, if you want to maintain Python 2 and Python 3 versions of your project
43-
simultaneously and with no differences, then you can write :ref:`Python 2/3
44-
source-compatible code <use_same_source>`. While the code is not quite as
45-
idiomatic as it would be written just for Python 3 or automating the port from
46-
Python 2, it does makes it easier to continue to do rapid development
47-
regardless of what major version of Python you are developing against at the
48-
time.
49-
50-
Regardless of which approach you choose, porting is probably not as hard or
34+
If you would prefer to maintain a codebase which is semantically **and**
35+
syntactically compatible with Python 2 & 3 simultaneously, you can write
36+
:ref:`use_same_source`. While this tends to lead to somewhat non-idiomatic
37+
code, it does mean you keep a rapid development process for you, the developer.
38+
39+
Finally, you do have the option of :ref:`using 2to3 <use_2to3>` to translate
40+
Python 2 code into Python 3 code (with some manual help). This can take the
41+
form of branching your code and using 2to3 to start a Python 3 branch. You can
42+
also have users perform the translation as installation time automatically so
43+
that you only have to maintain a Python 2 codebase.
44+
45+
Regardless of which approach you choose, porting is not as hard or
5146
time-consuming as you might initially think. You can also tackle the problem
5247
piece-meal as a good portion of porting is simply updating your code to follow
5348
current best practices in a Python 2/3 compatible way.
@@ -595,7 +590,8 @@ While it may seem counter-intuitive, you can write Python code which is
595590
source-compatible between Python 2 & 3. It does lead to code that is not
596591
entirely idiomatic Python (e.g., having to extract the currently raised
597592
exception from ``sys.exc_info()[1]``), but it can be run under Python 2
598-
**and** Python 3 without using 2to3_ as a translation step. This allows you to
593+
**and** Python 3 without using 2to3_ as a translation step (although the tool
594+
should be used to help find potential portability problems). This allows you to
599595
continue to have a rapid development process regardless of whether you are
600596
developing under Python 2 or Python 3. Whether this approach or using
601597
:ref:`use_2to3` works best for you will be a per-project decision.
@@ -611,8 +607,8 @@ the same source code.
611607
.. _What's New in Python 3.0: http://docs.python.org/release/3.0/whatsnew/3.0.html
612608

613609

614-
Follow The Steps for Using 2to3_ (sans 2to3)
615-
--------------------------------------------
610+
Follow The Steps for Using 2to3_
611+
--------------------------------
616612

617613
All of the steps outlined in how to
618614
:ref:`port Python 2 code with 2to3 <use_2to3>` apply
@@ -689,10 +685,11 @@ likely don't need it.
689685
Other Resources
690686
===============
691687

692-
The authors of the following blog posts and wiki pages deserve special thanks
693-
for making public their tips for porting Python 2 code to Python 3 (and thus
694-
helping provide information for this document):
688+
The authors of the following blog posts, wiki pages, and books deserve special
689+
thanks for making public their tips for porting Python 2 code to Python 3 (and
690+
thus helping provide information for this document):
695691

692+
* http://python3porting.com/
696693
* http://docs.pythonsprints.com/python3_porting/py-porting.html
697694
* http://techspot.zzzeek.org/2011/01/24/zzzeek-s-guide-to-python-3-porting/
698695
* http://dabeaz.blogspot.com/2011/01/porting-py65-and-my-superboard-to.html

0 commit comments

Comments
 (0)