Forrest logo
back to the 2to3 tool

2to3:tldr:19166

2to3: Convert specific Python 2 language features to Python 3.
$ 2to3 --write ${filename-py} --fix=${raw_input} --fix=${print}
try on your machine

The command "2to3 --write ${filename-py} --fix=${raw_input} --fix=${print}" is used for converting Python 2 code to Python 3 code using the 2to3 tool.

Let's break down the components of the command:

  • "2to3": This is the command for invoking the 2to3 tool in the command line. It is a built-in utility in Python that helps automate the conversion of Python 2 code to Python 3 code.

  • "--write": This flag is used to specify that the converted Python 3 code should be written back to the original file, overwriting the Python 2 code.

  • "${filename-py}": This is the placeholder for the name of the Python file that you want to convert. You need to replace "${filename-py}" with the actual name of the file, including the .py extension.

  • "--fix=${raw_input}": This flag is used to apply the fix for the deprecated use of the "raw_input" function in Python 2. By specifying "--fix=${raw_input}", it enables the conversion of instances where "raw_input" is used in Python 2 code to the equivalent functionality in Python 3.

  • "--fix=${print}": This flag is used to apply the fix for the change in syntax for the "print" statement between Python 2 and Python 3. By specifying "--fix=${print}", it enables the conversion of instances where the Python 2 "print" statement is used to the Python 3 "print" function.

In summary, this command takes a Python 2 file as input, applies the fixes for the deprecated "raw_input" and "print" functionalities, and converts the file to Python 3 code, overwriting the original file with the converted code.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the 2to3 tool