01调试与开发
调试做好,最简单的方法就是print,如果一个printa不好用那就用两个p(pprint),需要先导入这个库
from pprint import pprint
1 from pprint import pprint 2 a = ((‘x‘,‘y‘,2),(‘one‘,‘two‘,{‘1‘:2,‘3‘:4}),(‘love‘,‘fair‘,{‘1‘:2,‘2‘:4}),‘joy‘,‘renewjoy‘,{‘1‘:2,‘2‘:4}) 3 print(‘print:\n‘,a) 4 print(‘pprint:‘) 5 pprint(a)
结果:
1 print: 2 ((‘x‘, ‘y‘, 2), (‘one‘, ‘two‘, {‘1‘: 2, ‘3‘: 4}), (‘love‘, ‘fair‘, {‘1‘: 2, ‘2‘: 4}), ‘joy‘, ‘renewjoy‘, {‘1‘: 2, ‘2‘: 4}) 3 pprint: 4 ((‘x‘, ‘y‘, 2), 5 (‘one‘, ‘two‘, {‘1‘: 2, ‘3‘: 4}), 6 (‘love‘, ‘fair‘, {‘1‘: 2, ‘2‘: 4}), 7 ‘joy‘, 8 ‘renewjoy‘, 9 {‘1‘: 2, ‘2‘: 4})
02代码的比较
2.git 比较
git diff old.py new.py(个人不太喜欢)
1 -print "niaho python2" 2 -print "niaho python2" 3 +print("niaho python2") 4 +print("niaho python2")
2.cdiff比较
pip install cdiff
diff -u old.py new.py | cdiff(感觉还可以)
--- old.py 2019-06-08 10:57:14.091261538 +0800 +++ new.py 2019-06-08 10:58:32.254261665 +0800 @@ -1,2 +1,2 @@ -print "niaho python2" +print("niaho python2") -print "niaho python2" +print("niaho python2")
03排版与格式化
1美化格式
pip install yapf
yapf old.py > new.py # 将美化后的old.py 放在new.py中
yapf -i old.py # 使用-i 直接在源文件上修改
2.美化排版
pip install isort
isort -ls old.py #直接在源文件上进行美化排版
04辅助工具
1.man 手册
假如你忘记了sort在linux的用法,你可以查阅man手册 man sort ,最后你查到了
-i 将文件按 ASCII输出
2.cheat小抄
相当与精简版的man手册,使用方法与manh手册差不多 cheat sort
05实用推荐
1.创造一个临时服务器(python自带)
python3 -m http.server 6789
2.分布式任务队列-->celery+flower
3.自动化代码发布-->fabric
4.对进程进行监控的工具-->supervisor
原文:https://www.cnblogs.com/liu247/p/10990676.html