在2to3之上的一个黑客,用于使混合代码库的代码现代化。
modernize3k的Python项目详细描述
Python _ __ ___ __| |___ _ _ _ _ (_)______ | ' \/ _ \/ _` / -_) '_| ' \| |_ / -_) |_|_|_\___/\__,_\___|_| |_||_|_/__\___|
python modernize是lib2to3的一个很薄的包装器,可以利用它 Python2代码更加现代化,目的是最终将其移植到 Python3。这是一个非正式的叉子 https://github.com/mitsuhiko/python-modernize)在python 2和 三。
它不能保证,但它试图吐出一个python 2/3 兼容的代码库。
Unicode文本控件:
- 默认情况下,现代化将不使用文字。
- --future-unicode标志从 __future__模块。这需要Python2.6及更高版本,并且需要 使用b''和str(b'')中的本机字符串标记bytestrings,或者 类似的东西能在转变中幸存下来。
安装
来自PIP:
$ pip install --upgrade modernize3k
用法
预览文件或目录上的更改:
$ python-modernize example.py
写下更改:
$ python-modernize --write example.py
修改doctests而不是普通代码:
$ python-modernize --write --doctests example.py