全球人工智能:专注为AI开发者提供全球最新AI技术动态和社群交流。用户来源包括:北大、清华、中科院、复旦、麻省理工、卡内基梅隆、斯坦福、哈佛、牛津、剑桥等世界名校的AI技术硕士、博士和教授;以及谷歌、腾讯、百度、脸谱、微软、华为、阿里、海康威视、滴滴、英伟达等全球名企的AI开发者和AI科学家。
内容来源:GitHub 编译:马卓奇博士
github link: https://github.com/nvbn/py-backwards
需要Python3.3及以上版本运行,可以编译至2.7版本。
支持版本:
目标版本3.5
格式化字符串(formatted string literals),例如f'hi {x}'
变量声明( variables annotations),例如x: int = 10和x: int
数字串连接线(underscores in numeric literals),例如 1_000_000
目标版本3.4
带星号的展开(starred unpacking),例如 [*range(1, 5), *range(10, 15)]和print(*[1, 2], 3, *[4, 5])
字典展开(dict unpacking),例如{1: 2, **{3: 4}}
目标版本3.2
Yield from表达式
Return from generator表达式
目标版本2.7
函数声明(functions annotations)
导入(imports from__future__)
不用参数执行父类对象初始化(super without arguments)
没有父类的类(classes without base likeclass A: pass)
例如,如果你有Python3.6代码:
你可以用以下命令从Python2.7编译:
py-backwards -i input.py -o output.py -t 2.7
会得到一些不整齐的代码,保证它可以工作:
python3.6 input.py
val 10
0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10
{'x': 10, 'items': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}
10
11
python2 output.py
val 10
0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10
{'x': 10, 'items': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}
10
11
如何使用:
安装
pip install py-backwards
使用
py-backwards -i src -o compiled -t 2.7
开发
初始设置
pip install .python setup.py developpip install -r requirements.txt
运行测试
py.test
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|