python
文章平均质量分 58
kevin_darkelf
这个作者很懒,什么都没留下…
展开
-
marshmallow vs. pydantic – Python’s 2 best libraries for data serialization and validation
from : https://www.augmentedmind.de/2020/10/25/marshmallow-vs-pydantic-python/Data (de-) serialization is about converting between raw data items and instances of your Python classes, in order to transmit or store data. A typical example is the conversion转载 2021-11-16 16:00:55 · 1029 阅读 · 0 评论 -
Pydantic&FastAPI
Pydanticwhat is:Define how data should be in pure, canonical python; validate it with pydantic官网: https://pydantic-docs.helpmanual.io/Sample:from datetime import datetimefrom typing import List, Optionalfrom pydantic import BaseModelclass User原创 2021-10-07 20:10:00 · 278 阅读 · 0 评论 -
dict 和 object的转换
dict objectSEQS = tuple, list, set, frozenset class Jsonize(object): def __init__(self): super(Jsonize, self).__init__() def FromDict(d): this = Jsonize() # this = type(Jsonize.__name__, (Jsonize,), d) for k, v in d.items(原创 2021-05-29 21:17:45 · 301 阅读 · 0 评论 -
conda
安装获取安装包wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh 或者使用清华的源wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh 运行bash Miniconda3-latest-Linux-x86_64.sh 配置增加国内镜像源: conda原创 2021-05-17 15:42:51 · 113 阅读 · 0 评论 -
python 处理pdf
pdfminercode: https://github.com/pdfminer/pdfminer.sixdoc: https://pdfminersix.readthedocs.io原创 2020-11-17 15:30:55 · 101 阅读 · 0 评论 -
How To Package And Distribute Python Applications
IntroductionAll Python libraries (i.e. application packages) that you download using a package manager (e.g. pip) are distributed using a utility dedicated to do the job. These utilities create “Python distributions” which are basically versioned (and com原创 2020-10-03 16:54:10 · 267 阅读 · 0 评论 -
python 多线程多进程
Event多线程多进程 间同步可以使用 Event代码中是多线程, 使用 multiprocessing 的 Event,在处理系统信号的函数中 event.set() 卡死,换成 threading 的 Event 才对# from multiprocessing import Event from threading import Event glogger = logging.getLogger('')class ZService(object): stop_event =原创 2020-08-19 17:58:34 · 164 阅读 · 0 评论 -
c++/ python 混合编程多线程问题
c++调用pythonpython调用c++refpybind11.GIL原创 2020-07-09 11:16:02 · 589 阅读 · 0 评论 -
c++与python的数据交互
c++和python 都可以用pickle对数据进行序列化、反序列化,进而通过tcp/dup,pipe, shared memory 等方法进行通信PicklingTools: Cross Language Tools for Communication原创 2020-06-15 15:09:20 · 925 阅读 · 0 评论 -
python 对象
元类深入理解python之对象系统深入理解python之类的创建过程原创 2020-06-03 16:40:27 · 121 阅读 · 0 评论 -
python asyncio
解决python 异步并发refhttps://www.cnblogs.com/shenh/p/9090586.htmlhttps://www.cnblogs.com/zhaof/p/8490045.html原创 2020-06-02 11:23:16 · 101 阅读 · 0 评论 -
python 依赖
TODO可以用autoflake,autoremove 去除没有使用的依赖原创 2020-05-25 16:11:20 · 317 阅读 · 0 评论 -
java 调用python
jythonhttps://www.jython.org/原创 2020-05-20 14:36:40 · 103 阅读 · 0 评论 -
unittest for django models
import unittest from django.conf import settingsDATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'unittest.db', }}settings.configure(DATABASES =...原创 2020-04-29 14:22:37 · 93 阅读 · 0 评论 -
python coverage
TODO:ref:https://www.jianshu.com/p/7eaf04924be8https://coverage.readthedocs.io/en/latest/config.html原创 2020-04-07 22:07:01 · 151 阅读 · 0 评论 -
c++ invoke python
pybind11While pybind11 is mainly focused on extending Python using C++, it’s also possible to do the reverse: embed the Python interpreter into a C++ programref: https://pybind11.readthedocs.io/en...原创 2020-03-17 16:15:07 · 335 阅读 · 0 评论 -
python IPC
文件锁lockimport fcntlfd = open('lock_file', 'w+')fcntl.flock(fd.fileno(), fcntl.LOCK_EX)unlockimport fcntlfd = open('lock_file', 'w+')fcntl.flock(fd.fileno(), fcntl.LOCK_UN) try locki...原创 2020-02-10 15:14:42 · 315 阅读 · 0 评论 -
python 对象默认方法
TODO def __getitem__(self, item): if isinstance(item, six.string_types): return self.get_by_name(item) elif isinstance(item, (list, tuple)): return [self[it...原创 2020-02-06 15:50:07 · 470 阅读 · 0 评论 -
django model 开发
表名获取表名UserData._meta.db_table自定义表名class UserData(models.Model): ... class Meta: db_table = "user_data"group bypython:UserData.objects.filter(hubid=sensorid,time__range=(t...原创 2020-01-23 11:30:18 · 200 阅读 · 0 评论 -
WSGI
refpython WSGI框架详解深入理解uwsgi和gunicorn网络模型打造mvc框架之wsgi协议的优缺点及接口实现原创 2019-10-15 15:54:29 · 79 阅读 · 0 评论 -
python 格式化输出
使用print输出各型的字符串整数浮点数出度及精度控制strHello = Hello Pythonprint strHello#输出结果:Hello Python#直接出字符串1.格式化输出整数python print也支持参数格式化,与C言的printf似,strHello = "the length of (%s) is %d" %(Hello转载 2013-02-11 13:46:38 · 720 阅读 · 0 评论 -
Http Requests
timeout连接超时client 实现到远端机器端口的连接时(对应的是connect()_),Request 会等待的秒数一个很好的实践方法是把连接超时设为比 3 的倍数略大的一个数值,因为 TCP 数据包重传窗口 (TCP packet retransmission window) 的默认大小是 3。读取超时client 在连接到了服务器并且发送了 HTTP 请求之后,等待...原创 2019-06-25 21:15:47 · 147 阅读 · 0 评论 -
python 动态加载,子进程,重定向
python skill动态load module子进程stdout, stderr重定向sample codemain.pydef sub_proc(conf, task): import importlib _task = {} _task.update(task) task['status'] = 'running' pid = ...原创 2019-06-15 11:31:29 · 643 阅读 · 0 评论 -
Python垃圾回收机制:gc模块
ref:// https://www.cnblogs.com/kaituorensheng/p/4449457.html 在Python中,为了解决内存泄露问题,采用了对象引用计数,并基于引用计数实现自动垃圾回收。 由于Python 有了自动垃圾回收功能,就造成了不少初学者误认为不必再受内存泄漏的骚扰了。但如果仔细查看一下Python文档对 __del__() 函数的描述,就...转载 2018-08-01 21:14:07 · 494 阅读 · 0 评论 -
python virtaulenv
安装本机使用新建env激活修改 bin/activate安装其它所需模块代码开发退出env迁移使用virtualenv 搭建隔离的python环境,并能被移植到其它机器上直接运行 安装pip install virtualenv 本机使用新建env在工程中执行命令 virtualenv myenv 会在当前位置建立my...原创 2018-07-04 13:31:28 · 418 阅读 · 1 评论 -
Tornado实现多线程、多进程HTTP服务
背景 线上有一个相关百科的服务,返回一个query中提及的百科词条。该服务是用python实现的,以前通过thrift接口访问,现要将其改为通过HTTP访问。之前没有搭建HTTPServer的经验,因此想用python的web Framework来做这件事,于是有了下面的工作。第一部分是框架选择,这一部分没有太仔细考虑,只是大概看了一些文章。第二部分是根据所需要的功能,学习及测试在框架上应该如何...转载 2018-05-22 14:41:21 · 2468 阅读 · 1 评论 -
python invoking c++
invoking cc module from pythoncodebuildreferencesinvoking c/c++ module from pythonuse boost python codemodel_wrapper.cpp#include boost/python.hpp>#include boost/python/s原创 2018-01-18 15:10:48 · 348 阅读 · 0 评论 -
python 装饰器
from: http://www.cnblogs.com/rhcad/archive/2011/12/21/2295507.html第一步:最简单的函数,准备附加额外功能12345678# -*- coding:gbk -*-'''示例1: 最简单的函数,表示调用了两转载 2015-10-15 11:35:31 · 776 阅读 · 0 评论 -
python unittest tips
refhttp://pyunit.sourceforge.net/pyunit_cn.html原创 2016-04-24 21:17:39 · 317 阅读 · 0 评论 -
python lib error
无法在so中使用libpython.2.7.abuild error msg:/usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile wit原创 2016-06-15 16:40:09 · 3062 阅读 · 0 评论 -
concurrent http reader
并发读, 解决可能出现的超时#! coding: utf-8import sysimport osimport randomimport timeimport requestsfrom io import BytesIOimport sysfrom concurrent.futures import ProcessPoolExecutor, wait, FIRST_EXCEPTI...原创 2019-06-25 21:27:09 · 128 阅读 · 0 评论 -
python web framework
测试 flask, django, tornado 的 QPS部署采用性能较高的 gunicorn + gevent 部署方式,启动两个worker进程测试,通过长连接的方式发送get请求 /test?data=hellogunicorn 配置文件[works admin]$ cat gun.conf # -*- coding:utf-8 -*-#import osbind =...原创 2019-06-27 15:14:20 · 120 阅读 · 0 评论 -
搭建高性能的 Django 服务器栈
from:https://cloud.tencent.com/developer/article/1114765本文针对裸机 Linux 搭建 Django 的服务器栈,可直接应用在Linode等VPS上。Linux:Ubuntu 12.04 + ,其他版本类似说明:# 以#开头表示注释,$ 这里是需要执行的命令 <尖括号包含需要你自己定义的内容>○、连接VP...转载 2019-06-27 15:24:51 · 214 阅读 · 0 评论 -
python性能优化
优化点代码实现使用迭代器使用生成器避免频繁的访问同一属性cython利用cython 将计算逻辑转为cython,编译成so,有1~2倍的提速方法可参见https://blog.csdn.net/kevin_darkelf/article/details/98624120函数参数和返回值都使用 静态类型ref[python性能优化] (https://www...原创 2019-09-23 20:51:21 · 118 阅读 · 0 评论 -
k8s 部署python服务
djangohttps://blog.csdn.net/bbwangj/article/details/82943452https://blog.csdn.net/qq_24095941/article/details/85761609原创 2019-08-10 16:47:01 · 1091 阅读 · 0 评论 -
python源码的保护
不想直接暴露python 源代码,cython依赖cythonsudo pip install cython gccpython dev通过源码编译安装的python 自带, 可以通过查找 Python.h 确认验证代码setup.pyfrom distutils.core import setupfrom Cython.Build import cython...原创 2019-08-06 16:15:18 · 713 阅读 · 0 评论 -
python list dict sort
listlist 元素为dict ,按某键的value排序, 默认升序l = [{'name':'tom', 'age': 19}, {'name':'joj', 'age': 20}, {...}] sorted_list = sorted(l, key = lambda x : x['age']) dict按value 排序,降序sorted_list = sorte...原创 2019-07-06 12:13:42 · 440 阅读 · 0 评论 -
python ConcurrentLogHandler
git: https://github.com/Preston-Landers/concurrent-log-handler原创 2019-07-09 20:07:08 · 793 阅读 · 0 评论 -
nginx,uwsgi,gunicorn, flask,django
nginx+uwsgi 和nginx+gunicorn区别、如何部署使用uwsgi和gunicorn部署Django项目深入理解uwsgi和gunicorn网络模型原创 2019-06-28 08:20:23 · 120 阅读 · 0 评论 -
python 常用正则
查找变量 ${VAR}p = r'(?<=\$\{).+?(?=\})'s = '/${path}/P/${VERSION}/sdk ' print re.findall(p, s) ['path', 'VERSION']原创 2019-07-08 21:02:06 · 375 阅读 · 0 评论