Friday, October 5, 2018

2to3 - Python2 to Pyton3 Converter in archlinux

2to3. 2to3 is a part of the python application. So if you install a python application on archlinux, this 2to3 can be directly used. 2to3 is a linux command. 2to3 is a linux command that functions to convert python2 to python3.



Installation in archlinux:
$sudo pacman -S python
How to usage:
2to3 [options] filelocations

Examples: test.py (python2)
 def greet(name):
    print "Archlinux, {0}!".format(name)
print "The best Distros"
name = raw_input()
greet(name)
Command to convert test.py
2to3 test.py
The results will be like this
def greet(name):
    print("Archlinux, {0}!".format(name))
print("The best Distros")
name = input()
greet(name)
More options: "2to3 --help
Usage: 2to3 [options] file|dir ...
Options:
  -h, --help            show this help message and exit
  -d, --doctests_only   Fix up doctests only
  -f FIX, --fix=FIX     Each FIX specifies a transformation; default: all
  -j PROCESSES, --processes=PROCESSES
                        Run 2to3 concurrently
  -x NOFIX, --nofix=NOFIX
                        Prevent a transformation from being run
  -l, --list-fixes      List available transformations
  -p, --print-function  Modify the grammar so that print() is a function
  -v, --verbose         More verbose logging
  --no-diffs            Don't show diffs of the refactoring
  -w, --write           Write back modified files
  -n, --nobackups       Don't write backups for modified files
  -o OUTPUT_DIR, --output-dir=OUTPUT_DIR
                        Put output files in this directory instead of
                        overwriting the input files.  Requires -n.
  -W, --write-unchanged-files
                        Also write files even if no changes were required
                        (useful with --output-dir); implies -w.
  --add-suffix=ADD_SUFFIX
                        Append this string to all output filenames. Requires
                        -n if non-empty.  ex: --add-suffix='3' will generate
                        .py3 files.
Examples to write back modified files:
$2to3 -w test.py
For More documentation you can see on pyton docs:
https://docs.python.org/3/library/2to3.html
https://docs.python.org/2/library/2to3.html
Share on Facebook
Share on Twitter
Share on Google+
Tags :