Forrest logo
tool overview
On this page you find all important commands for the CLI tool 2to3. If the command you are looking for is missing please ask our AI.

2to3

2to3 is a command line tool used for converting Python 2.x code to Python 3.x code. It is a part of the standard distribution of Python. This tool helps automate the process of migrating code written in Python 2 to Python 3, which can be necessary when transitioning to newer versions of Python. 2to3 analyzes the source code for syntactic and semantic differences between Python 2 and Python 3 and applies the necessary transformations to make the code valid in Python 3. It replaces or modifies various components such as print statements, imports, and syntax changes to make the code compatible. The tool generates a diff file showing the changes made, making it easy to review and manually adjust the converted code as needed. 2to3 also provides various options for customizing the conversion process, such as fixing specific types of issues, dealing with certain incompatibilities, and generating warnings or error messages. It is widely used by developers and organizations to streamline the migration of code from Python 2 to Python 3.

List of commands for 2to3:

  • 2to3:tldr:08203 2to3: Convert a Python 2 file to Python 3.
    $ 2to3 --write ${filename-py}
    try on your machine
    explain this command
  • 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
    explain this command
  • 2to3:tldr:40dc8 2to3: Display a list of all available language features that can be converted from Python 2 to Python 3.
    $ 2to3 --list-fixes
    try on your machine
    explain this command
  • 2to3:tldr:4c0e4 2to3: Convert all Python 2 files in a directory to Python 3.
    $ 2to3 --output-dir=${path-to-python3_directory} --write-unchanged-files --nobackups ${path-to-python2_directory}
    try on your machine
    explain this command
  • 2to3:tldr:4df69 2to3: Convert all Python 2 language features except the specified ones to Python 3.
    $ 2to3 --write ${filename-py} --nofix=${has_key} --nofix=${isinstance}
    try on your machine
    explain this command
  • 2to3:tldr:bb762 2to3: Run 2to3 with multiple threads.
    $ 2to3 --processes=${4} --output-dir=${path-to-python3_directory} --write --nobackups --no-diff ${path-to-python2_directory}
    try on your machine
    explain this command
  • 2to3:tldr:d4360 2to3: Display the changes that would be performed without performing them (dry-run).
    $ 2to3 ${filename-py}
    try on your machine
    explain this command
tool overview