python2代码升级到python3工具
Posted buyizhiyou
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python2代码升级到python3工具相关的知识,希望对你有一定的参考价值。
python模块lib2to3(py2转py3自动化工具)
1 Usage: 2to3 [options] file|dir ... 2 3 Options: 4 -h, --help show this help message and exit 5 -d, --doctests_only Fix up doctests only 6 -f FIX, --fix=FIX Each FIX specifies a transformation; default: all 7 -j PROCESSES, --processes=PROCESSES 8 Run 2to3 concurrently 9 -x NOFIX, --nofix=NOFIX 10 Prevent a transformation from being run 11 -l, --list-fixes List available transformations 12 -p, --print-function Modify the grammar so that print() is a function 13 -v, --verbose More verbose logging 14 --no-diffs Don‘t show diffs of the refactoring 15 -w, --write Write back modified files 16 -n, --nobackups Don‘t write backups for modified files 17 -o OUTPUT_DIR, --output-dir=OUTPUT_DIR 18 Put output files in this directory instead of 19 overwriting the input files. Requires -n. 20 -W, --write-unchanged-files 21 Also write files even if no changes were required 22 (useful with --output-dir); implies -w. 23 --add-suffix=ADD_SUFFIX 24 Append this string to all output filenames. Requires 25 -n if non-empty. ex: --add-suffix=‘3‘ will generate 26 .py3 files.
eg:2to3 -w test.py
以上是关于python2代码升级到python3工具的主要内容,如果未能解决你的问题,请参考以下文章