Porting code to Python 3__python using 2to3

Source: Internet
Author: User

Http://woodpecker.org.cn/diveintopython3/porting-code-to-python-3-with-2to3.html


Abstrac:


Almost all of the Python 2 programs require some modification to run normally in the Python 3 environment. To simplify the conversion process, Python 3 brings up a utility script called 2to3 (Utility script), which takes your Python 2 program source file as input and automatically converts it to Python 3. Case study: Porting Chardet to Python 3 (porting Chardet to Python 3) describes how to run this script and then shows some cases where it cannot be automatically repaired. This appendix describes the content that it can automatically fix. Print Statement #

In Python 2, print is a statement. Whatever you want to output, just put them behind the print keyword. In Python 3, print () is a function. Like other functions, print () requires you to pass the object you want to output as an argument.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.