python2代码转python3

Python官方有一个转换工具:2to3-script.py。无论是python还是Anaconda,2to3-script.py都在…\Tools\scripts里面。将scipt所在路径加入环境变量,2to3.exe与 2to3-script.py效果是一样的。

python   2to3-script.py 与2to3.exe是等价的。

示例1:2to3.exe  -w  -n D:\new\sample ,将sample路径下所有python2文件转换到原位置、不备份。

示例2:2to3.exe  -w  -n D:\new\sample\test.py ,将sample路径test.py下所有python2文件转换到原位置、不备份

2to3.exe   --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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值