如何将您的代码库从 Python2 迁移到 Python3? [英] How to migrate your codebase from Python2 to Python3?

查看:81
本文介绍了如何将您的代码库从 Python2 迁移到 Python3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑将我的 Python2.x 代码库迁移到 python3.x.我的预期是做以下事情:

I'm thinking to migrate my Python2.x codebase to python3.x. My anticipation is to do the following things:

  1. 在 Python3 中迁移 Python2 语法
  2. 迁移所有使用的与 Python3 兼容的包和库
  3. 确保所有测试(单元测试)在迁移期间和之后都通过并迭代修复.

你有什么建议?提前致谢!

What are your suggestions? Thanks in advance!

推荐答案

项目 2to3 对此非常有帮助.

The project 2to3 is very helpful with this.

它可以处理需要发生的最常见的 Python2->Python3 代码更改.您也可以在测试中运行它.从那里我会得到一个 Python3 虚拟环境,安装 pylint,并检查你的代码库.

It can take care of the most common Python2->Python3 code changes that need to take place. You can run this on your tests also. From there I'd get a Python3 virtual environment, install pylint, and lint your codebase.

对于大型代码库,从 2 到 3 的迁移过程可能有点麻烦.这篇文章做了深入的解释.

The migration process from 2 to 3 can be a bit cumbersome for large codebases. This article does a great job with in-depth explanations.

这篇关于如何将您的代码库从 Python2 迁移到 Python3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆