python通用工具
python-common-tools的Python项目详细描述
一些常用的python工具箱
安装
pip3 install python_common_tools
使用
importtime# 使得函数使用缓存frompython_common_tools.cacheimportcache_function,cache_daily_function@cache_function('.')deff(self,a,b,c):time.sleep(3)returna+b+c@cache_daily_function('.')deff2(self,a,b,c):time.sleep(3)returna+b+c# 快速设置日志frompython_common_tools.logimportsetup_loggerlogger=setup_logger("test.log")# 搞定异常处理的网络请求frompython_common_tools.networkimportsecure_requests,secure_requests_jsonresp=secure_requests("https://www.gethtml.com/test",retry_times=3,log_err=True)j=secure_requests_json("https://www.getjson.com/test",timeout=10)# linux系统相关的获取命令执行结果 获取最新版本号 打开远程服务器上的文件frompython_common_tools.linuximportget_bash_output,get_latest_commit_id,open_remote_filedirfiles=get_bash_output(["ls","-l"])commit_id=get_latest_commit_id()