摘要:一、安装及简单实用 1.安装并加入环境变量 wget https://releases.hashicorp.com/consul/1.5.1/consul_1.5.1_linux_amd64.zip unzip consul_1.5.1_linux_amd64.zip -d /usr/local/b
阅读全文
摘要:索引虽好,但也不是无限制的使用,最好符合一下几个原则 1) 最左前缀匹配原则,组合索引非常重要的原则,mysql会一直向右匹配直到遇到范围查询(>、<、between、like)就停止匹配,比如a = 1 and b = 2 and c > 3 and d = 4 如果建立(a,b,c,d)顺序的索
阅读全文
摘要:where 根据id查询记录,因为id字段仅建立了主键索引,因此此SQL执行可选的索引只有主键索引,如果有多个,最终会选一个较优的作为检索的依据。 -- 增加一个没有建立索引的字段alter table innodb1 add sex char(1);-- 按sex检索时可选的索引为nullEXPL
阅读全文
摘要:配置方法: (1) 直接在文件中 写 app.config['xxx'] = 'xxx' app.config['DEBUG'] = True PS: 由于Config对象本质上是字典,所以还可以使用app.config.update(...) 注意: 某个对象 可以进行 a['aa'] = 111
阅读全文
摘要:_credit_id_weight = ( 1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28) def _is_credit_id_valid(oid: str) -> bool: if not isinstance(oid
阅读全文
摘要:_natual_id_weight = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2) def _is_natural_id_valid(oid: str) -> bool: if not isinstance(oid, str) or l
阅读全文
摘要:源码: def op(self, opstring, precedence=0, is_comparison=False): """produce a generic operator function. e.g.:: somecolumn.op("*")(5) produces:: somecol
阅读全文
摘要:最简单的hello world #!/usr/bin/env python # encoding: utf-8 from flask import Flask app = Flask(__name__) @app.route('/') def index(): return 'hello world
阅读全文
摘要:web网站包含前端和后端, 异步处理可以用在前端, 也可以用在后端. 前端 jquery 进行 ajax 请求时, 可设置 async 属性为 true, 并为 success 设置一个 callback 函数, 在服务端返回之前, 浏览器可以执行 ajax 之后的代码, 当服务器端返回后, jqu
阅读全文
摘要:转载:https://www.cnblogs.com/harrychinese/archive/2012/09/12/My_Own_Tutorial_For_SqlAlchemy.html 使用 sqlalchemy 有3种方式:方式1, 使用raw sql;方式2, 使用SqlAlchemy的sq
阅读全文
摘要:源码:class cached_property(object): """ Decorator that converts a method with a single self argument into a property cached on the instance. Optional ``
阅读全文
摘要:作用:封装sql字符串 1. 不同数据库, 可以使用统一的sql参数传递写法. 参数须以:号引出. 在调用execute()的时候, 使用dict结构将实参传进去. from sqlalchemy import text result = db.execute(text('select * from
阅读全文
摘要:class Entry(AbstractConcreteBase, db.Model): """Base Class of Entry.""" id = db.Column(db.Integer, primary_key=True, nullable=False) created = db.Colu
阅读全文
摘要:Concrete Table Inheritance译成混合继承? 这种继承方式会创建一个ORM基类,然后在所有继承表中会创建包含ORM基类定义的字段的独立的表。 继承表与ORM基类的关系在数据库层面上没有外健关系,只是在语言层会有继承关系。 class Employee(AbstractConcr
阅读全文
摘要:Single Table Inheritance即单表继承,顾名思义,所有继承表的数据均保存在一个表。 该种继承比较容易理解。 class Employee(Base): __tablename__ = 'employee' id = Column(Integer, primary_key=True
阅读全文
摘要:Joined Table Inheritance指通过外健方式进行链接实现的继承方式。 举个例子理解,共三个ORM类: Employee:员工,基类,具有id,name两个共有字段Manager:经理,继承Employee Engineer:工程师,继承Employee,在本例中,SQLAlchem
阅读全文
摘要:线程与进程 进程: 我们都知道计算机的核心是CPU,它承担了所有的计算任务;而操作系统是计算机的管理者,它负责任务的调度、资源的分配和管理,统领整个计算机硬件;应用程序侧是具有某种功能的程序,程序是运行于操作系统之上的。 (为了缓解头脑胀痛, 斜体字大体过一遍即可) 进程是一个具有一定独立功能的程序
阅读全文
摘要:原因:未配置环境变量 解决:我安装gunicorn用的pip3,所以找到python3的bin目录,将入环境变量即可 export PATH=$PATH:/usr/local/python3/bin
阅读全文
摘要:适配器模式 Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of in
阅读全文
摘要:django中的继承有三类; 1.抽象继承 2.多表继承 3.proxy model(代理模型) 第1种情况表示你的父类仅仅是包含了多个子类的相同的字段,是为了重用,不会建表,我们只需要在抽象父类的Meta中设置abstract=True就行。比如: class CommonInfo(models.
阅读全文
摘要:监听模式中,建了模式父类 class Observer(ABCMate): @abstractmethod def update(self,waterHeater): pass 洗澡模式: class WashingMode(Observer): def update(self,waterHeate
阅读全文
摘要:from abc import ABC,abstractmethod from collections import namedtuple ##############商品类############## class Item: def __init__(self,name,price,num): s
阅读全文
摘要:一、CAP原则 CAP原则又称CAP定理,指的是在一个分布式系统中, Consistency(一致性)、 Availability(可用性)、Partition tolerance(分区容错性),三者不可得兼。 CAP原则是NOSQL数据库的基石。 分布式系统的CAP理论:理论首先把分布式系统中的三
阅读全文
摘要:秒杀:秒杀是通常意味着要在很短的时间处理极高的并发,系统在短时间需要承受平时百倍以上的流量,因此秒杀架构是一个比较复杂的问题,其核心思路是流量控制和性能优化,需要从前端(通过JavaScript实现倒计时、避免重复提交和限制频繁刷新)到后台各个环节的配合。流量控制主要是限制只有少部分流量进入服务后端
阅读全文
摘要:import smtplib from email import (header) from email.mime import (text, application, multipart) import time def sender_mail(): smt_p = smtplib.SMTP()
阅读全文
摘要:兴高采烈地,从网页上抓取一段 content 但是,一 print 就不那么兴高采烈了,结果看到一串这个: b'\xc8\xcb\xc9\xfa\xbf\xe0\xb6\xcc\xa3\xac\xce\xd2\xd3\xc3Python' 这是啥? 又 x 又 c 的! 再一看,哦,原来是十六进制字
阅读全文
摘要:一行代码优化输出的异常信息 pip install pretty-errors 写一个函数测试: def divided_zero(): for i in range(10, -1, -1): print(10/i) divided_zero() 在没有import这个pretty-errors前,
阅读全文
摘要:array = [1, 3, 5] g = (x for x in array if array.count(x) > 0) g为生成器,list(g)后返回[1,3,5],因为每个元素肯定至少都出现一次。所以这个结果这不足为奇。但是,请看下例: array = [1, 3, 5] g = (x f
阅读全文
摘要:创建一个类SE: class SE(object): def __init__(self): print('init') def __del__(self): print('del') 创建两个SE实例,使用is判断: In [63]: SE() is SE() init init del del
阅读全文
摘要:In [1]: a = 'something' ...: b = 'some'+'thing' ...: id(a)==id(b) Out[1]: True 如果上面例子返回True,但是下面例子为什么是False: In [1]: a = '@zglg.com' In [2]: b = '@zgl
阅读全文
摘要:1 turtle绘制奥运五环图 import turtle as p def drawCircle(x,y,c='red'): p.pu()# 抬起画笔 p.goto(x,y) # 绘制圆的起始位置 p.pd()# 放下画笔 p.color(c)# 绘制c色圆环 p.circle(30,360) #
阅读全文
摘要:1#测试函数执行时间的装饰器示例 import time def timing_func(fn): def wrapper(): start=time.time() fn() #执行传入的fn参数 stop=time.time() return (stop-start) return wrapper
阅读全文
摘要:1 寻找第n次出现位置 def search_n(s, c, n): size = 0 for i, x in enumerate(s): if x == c: size += 1 if size == n: return i return -1 print(search_n("fdasadfadf
阅读全文
摘要:4G 内存处理 10G 大小的文件,单机怎么做? 下面的讨论基于的假定:可以单独处理一行数据,行间数据相关性为零。 方法一: 仅使用 Python 内置模板,逐行读取到内存。 使用 yield,好处是解耦读取操作和处理操作: def python_read(filename): with open(
阅读全文
摘要:1.主线程 import threading t = threading.current_thread() print(t) # <_MainThread(MainThread, started 139908235814720)> print(t.getName()) # MainThread pr
阅读全文
摘要:1.年的日历图 import calendar from datetime import date mydate = date.today() year_calendar_str = calendar.calendar(2019) print(f"{mydate.year}年的日历图:{year_c
阅读全文