How to use 2to3 properly for python?

后端 未结 9 905
野趣味
野趣味 2020-12-04 17:26

I have some code in python 2.7 and I want to convert it all into python 3.3 code. I know 2to3 can be used but I am not sure exactly how to use it.

9条回答
  •  攒了一身酷
    2020-12-04 17:59

    It's important to have a backup before running 2to3.

    1. If you're using git, make a commit.
    2. Otherwise, make a backup copy of your files.

    First, run 2to3 in "soft mode" to see what it would actually do:

    $ 2to3 /path/to/your/project
    

    If you're happy with what it would do, you can then run 2to3 "for real":

    $ 2to3 --write --nobackups /path/to/your/project
    

    And now you have properly run 2to3 :)

提交回复
热议问题