基于2to3的混合代码库代码现代化的一种改进。
项目描述
Python _ __ ___ __| |___ _ _ _ _ (_)______ | ' \/ _ \/ _` / -_) '_| ' \| |_ / -_) |_|_|_\___/\__,_\___|_| |_||_|_/__\___|
python-modernize是lib2to3的一个非常薄的包装器,利用它将Python 2代码现代化,目的是最终将其迁移到Python 3。这是一个非官方分支(https://github.com/mitsuhiko/python-modernize),在Python 2和3上均可运行。
它不保证,但试图输出一个Python 2/3兼容的代码库。
Unicode文字控制
默认情况下,modernize将保留文字。
使用--future-unicode标志从__future__模块导入unicode_literals。这需要Python 2.6及以后版本,并且需要您用b''标记字节数组,并在str(b'')或类似的结构中标记原生字符串,以便在转换过程中保持不变。
安装
从pip
$ pip install --upgrade modernize3k
使用
预览文件或目录的更改
$ python-modernize example.py
写入更改
$ python-modernize --write example.py
修改doctests而不是普通代码
$ python-modernize --write --doctests example.py
测试
测试使用cram
$ cram --indent=4 test.cram