![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
木叶之秋
这个作者很懒,什么都没留下…
展开
-
记一次python mem排错
docker run 一个容器(多个测试样例)。结果显示 有个测试样例被 killed 。docker stats 查看 ,发现内存接近90G;而我实际运行时 只有 1G的内存。所以被killed。[root@a34h05007.cloud.h05.amtest87 /root]#docker stats --no-stream|head -n 1;while [[ true ]];do e...原创 2020-01-02 10:02:08 · 294 阅读 · 1 评论 -
python unittest.TestCase
unittest.Testcase : https://docs.python.org/zh-cn/3/library/unittest.html测试样例, 文档函数名需要 “test” 开头,才能被应用Ran 0 tests in 0.000s 这个测试样例 没有 被应用import unittestclass test_myClass(unittest.TestCase): ...原创 2019-11-28 17:39:49 · 328 阅读 · 0 评论 -
yaml按顺序 load,dump,&& 去掉 yaml.dump的“null”
yaml 按顺序 load,dump当你有一个 map.里面有dict,list各种的时候, 如果你用 yaml.load,yaml.dump,你会发现他的顺序有变了, 当你不洗碗他变的时候, 怎么办??from collections import OrderedDictimport yamldef ordered_yaml_load(yaml_path, Loader=yaml.Lo...原创 2019-08-15 16:04:58 · 3100 阅读 · 0 评论 -
常用正则表达式
验证数字的正则表达式集验证数字:1$验证n位的数字:^\d{n}$验证至少n位数字:^\d{n,}$验证m-n位的数字:^\d{m,n}$验证零和非零开头的数字:^(0|[1-9][0-9])$验证有两位小数的正实数:2+(.[0-9]{2})?$验证有1-3位小数的正实数:3+(.[0-9]{1,3})?$验证非零的正整数:^+?[1-9][0-9]$验证非零的负整数:^-[1...原创 2019-05-05 17:32:04 · 215 阅读 · 0 评论 -
python学习
官方文档(https://docs.python.org/zh-cn/3/library/typing.html)cookbook(https://python3-cookbook.readthedocs.io/zh_CN/latest/c07/p03_attach_informatinal_matadata_to_function_arguments.html)给函数参数增加元信息你写好了...原创 2019-04-24 09:47:37 · 437 阅读 · 2 评论 -
Python多线程报错之RuntimeError
写多线程脚本,运行的时候报错File “/usr/local/lib/python2.6/threading.py”, line 465, in startraise RuntimeError(“thread.init() not called”)RuntimeError: thread.init() not called原因是线程类中构造函数__init__()中未调用父类的初始化方法,...转载 2019-04-18 11:19:55 · 1055 阅读 · 0 评论 -
ubuntu 下安装nanomsg和nnpy
nanomsgnanomsg是ZeroMQ作者用C语言重写的一个Socket库,其用法和模式和ZeroMQ差不多,但是具有更好的性能和更完善的接口。首先下载源码wget https://github.com/nanomsg/nanomsg/archive/1.0.0.tar.gz -O nanomsg-1.0.0.tar.gz首先确保你ubuntu上已经安装gcc gcc-c++ pyt...转载 2019-04-21 14:21:42 · 1632 阅读 · 0 评论 -
python 打印top的信息到log
管道,批次,def echo_in_log(metric,threshold): top1_info = subprocess.Popen(["top", "-n", "1","-b"],stdout=subprocess.PIPE) top_info = subprocess.Popen(["head","-n","30"],stdin=top1_i原创 2019-03-01 17:41:52 · 518 阅读 · 0 评论 -
python 中文排序(按拼音)
pypinyin排序 仅按拼音首字母 排序安装pypinyinpip3 install pypinyin代码from pypinyin import lazy_pinyinchars = ['鑫','鹭','榕','柘','珈','骅','孚','迦','瀚','濮','浔','沱','泸','恺','怡','岷','萃','兖']chars.sort(key=lambda ch...原创 2019-01-26 16:54:58 · 3504 阅读 · 0 评论 -
docker环境变量
docker中获取环境变量docker中的文件配置文件 (python 获取)API_ADDR = os.environ.get(“API_ADDR”,“http://127.0.0.1:8080/api/v1”cat rrd/config.pyimport osAPI_ADDR = os.environ.get("API_ADDR","http://127.0.0.1:8080/a...原创 2018-12-17 21:49:59 · 1769 阅读 · 0 评论 -
python填坑(1)
return执行到return语句时,会退出函数,return之后的语句不再执行。。。但将return语句放在try语句块中,是个例外。。。。def fun(): print(kk) return 'ok'#执行到该return语句时,函数终止,后边的语句不再执行 print(kk) def func(): try: print(kk) ...原创 2019-01-29 12:01:04 · 598 阅读 · 0 评论 -
爬虫直接用cookie
感谢(https://www.douban.com/note/264976536/)1,获取Cookie很简单,使用Chrome浏览器的”开发者工具(Developer Tools)“或者Firefox的"HTTPFOX"等插件就可以直接查看自己新浪微博的Cookie。(注: 这个私人Cookie千万不要泄露哦!)比如,Chrome原创 2018-12-09 16:57:25 · 648 阅读 · 0 评论 -
python中logging的运用
参考链接(https://segmentfault.com/a/1190000003008066)(https://blog.csdn.net/z_johnny/article/details/50812878)快速应用import loggingfrom logging.handlers import TimedRotatingFileHandler #加载模块gp...转载 2018-12-05 14:14:42 · 383 阅读 · 0 评论 -
python3中的一些坑
参考链接(https://www.kawabangga.com/posts/2245)理解Python的UnboundLocalError(Python的作用域)今天写代码碰到一个百思不得解为什么会出错的代码,简化如下:x = 10def func(): if something_true(): x = 20 print(x) func()意图很明显...转载 2018-12-05 10:57:35 · 413 阅读 · 0 评论 -
Python中 sys.argv[]
参考链接(https://www.cnblogs.com/aland-1415/p/6613449.html)sys.argv[] 就是用来执行脚本时,向脚本里传入参数的python XX.py kkkk #就是给XX.py 传入了kkkk的参数。也可以是多个, 详见例子。直接传入,print(sys.argv) G:\python\day2>python argv.py...原创 2018-11-07 21:34:17 · 135 阅读 · 0 评论