如何將 Python 2 的程式碼移植到 Python 3

作者:

Brett Cannon

Python 2 reached its official end-of-life at the start of 2020. This meansthat no new bug reports, fixes, or changes will be made to Python 2 - it'sno longer supported: seePEP 373 andstatus of Python versions.

If you are looking to port an extension module instead of pure Python code,please see遷移延伸模組到 Python 3.

The archivedpython-porting mailing list may contain some useful guidance.

Since Python 3.11 the original porting guide was discontinued.You can find the old guide in thearchive.

Third-party guides

There are also multiple third-party guides that might be useful: