python基础===monkeytype可以自动添加注释的模块!
2018-01-17 16:20
603 查看
monkeytype 一个可以自动添加注释的模块!
先要下载:
pip install monkeytype
以官网的sample code为例
#moudle.py def add(a, b): return a + b
这个test.py的文件会调用add()方法
#test.py
from module import add print(add(1, 2))
我们在cmd窗口执行如下命令:
monkeytype run test.py
程序执行完毕,可以看到返回了3
ok!重点来了,我们发现多了一个monkeytype.sqlite3文件。
官网解释是这样的:
By default this will dump call traces into a sqlite database in the file
monkeytype.sqlite3in the current working directory. You can then use themonkeytypecommand to generate a stub file for a module, or apply the type annotations directly to your code.
在cmd下执行命令:
monkeytype stub some.module
可以清楚的看到对a 和 b ,以及add方法的注释
应用注释到代码中:
monkeytype apply some.module
再看module.py文件:
代码已经自动打上注释了。
详细操作指南,参考:
http://monkeytype.readthedocs.io/en/latest/index.html#
相关文章推荐
- html基础 每个模块可以添加注释信息 <!-- start:xxx -->...<!-- end:xxx -->
- Python3基础 sys.path.append 增加模块的搜索路径,在主代码处新建一个存放模块的文件夹并将其路径添加到sys.path中
- python_基础总结1 python由来 字符编码 注释 pyc文件 python变量 导入模块 获取用户输入 流程控制if while
- 用vba写的自动添加源文件的宏,可以用来方便添加c++源文件的头注释
- 基础入门_Python-模块和包.深入Celery之任务绑定/记录日志/自动重试?
- 浅谈Python脚本开头及导包注释自动添加方法
- Python之Fabric模块 Fabric是基于Python实现的SSH命令行工具,简化了SSH的应用程序部署及系统管理任务,它提供了系统基础的操作组件,可以实现本地或远程shell命令,包括:
- Python基础-文档测试(自动执行注释中的代码)
- python爬虫主要就是五个模块:爬虫启动入口模块,URL管理器存放已经爬虫的URL和待爬虫URL列表,html下载器,html解析器,html输出器 同时可以掌握到urllib2的使用、bs4(BeautifulSoup)页面解析器、re正则表达式、urlparse、python基础知识回顾(set集合操作)等相关内容。
- Python中关于使用模块的基础知识
- 在python中添加自定义模块
- Python基础(12)--模块
- python基础要点(4)-模块
- python基础之模块
- [Vim]新建python文件自动添加python header
- Python扩展包安装方法以及Python添加库(模块)
- Python 基础学习之安装python及其模块安装
- vim自动添加文件注释
- python基础——第三方模块
- Python基础模块