We can convert Python2 scripts to Python3 scripts by using 2to3 module. It changes Python2 syntax to Python3 syntax. We can change all the files in a particular folder from python2 to python3.
This module does not come built-in with Python. To install this type the below command in the terminal.
pip install 2to3
2to3 [file or folder] -w
If we want to change all files in the currently open folder and all the files in the subfolder from Python2 to Python3 type the below command.
If we want to change a particular file in the current folder from Python2 to Python3 then enter the following command.
2to3 gfg.py -w
Example: Consider a simple Python2 file.
To convert this file from Python2 to Python3 open the terminal in the directory containing the file and type the below command.
The Python file will now be converted to Python3. Let’s see the file.
- Python2 vs Python3 | Syntax and performance Comparison
- Automate linkedin connections using Python
- PyQt5 - How to automate Progress Bar while downloading using urllib?
- Python | Automate Google Search using Selenium
- Automate getter-setter generator for Java using Python
- Itertools in Python3
- Introduction to Python3
- New '=' Operator in Python3.8 f-string
- Positional-only Parameter in Python3.8
- Python3 for GUI application | An Overview
- How to implement Dictionary with Python3?
- Why PyPy3 is preffered over Python3?
- How to write Comments in Python3?
- How to print spaces in Python3?
- Different Input and Output Techniques in Python3
- Convert String to Double in Python3
- Python3 - if , if..else, Nested if, if-elif statements
- Python3 Intermediate Level Topics
- Setting python3 as Default in Linux
- Mahotas - RGB to XYZ Conversion
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.