- 博客(84)
- 收藏
- 关注
转载 urllib库
* ua = random.choice(ua_list) #随机选择一个user-agent信息* request = Request(url) #传奇请求对象* request.add_header('User-Agent', ua) #添加请求头信息* response.read() # 读取返回的内容
2019-07-28 23:35:53
167
原创 lxml,etree简单爬取数据
# //div[@class='billboard-bd']//a/text()import requestsfrom lxml import etreeurl = 'https://movie.douban.com/'headers = {'User-agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTM...
2019-07-27 23:06:37
342
原创 request库
from requests.models import Responseimport requestsurl = 'https://movie.douban.com/'res:Response = requests.request("GET", url, headers={'User-agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWe...
2019-07-27 20:20:05
167
原创 celery
from celery import Celeryapp = Celery()print(app)@app.task(name='myfirsttask')def add(x, y): print('enter ~~~') ret = x + y import time time.sleep(10) return retprint(app...
2019-07-26 17:16:43
107
转载 Django模板技术
Django模板技术urls配置templates/indexDTL语法urls配置from django.template import loaderfrom django.http import JsonResponse, HttpRequest, HttpResponsefrom django.shortcuts import renderdef index(request)...
2019-07-22 19:11:18
173
原创 js的MiXin技术
const A = cls => class extends cls { //函数A返回一个继承自cls的子类 constructor (...arges){ console.log('A') super(...arges); if (typeof (this.stri) !=='function'){ //判断子类是否有stri方...
2019-07-09 22:06:17
288
原创 Promise
var promise = new Promise( function (resolve,reject) { console.log('do some thing') resolve('dit it') console.log('~~~~~~~~~~~') reject('failed') });var p1= ...
2019-07-06 17:54:15
112
原创 对象操作
var obj = { a:100, b:200, c:300,}console.log(obj.a,obj.b,obj.c)var new1 = Object.keys(obj)var values = Object.values(obj)var entries = Object.entries(obj)console.log(new1)console....
2019-07-06 16:40:38
169
原创 文件拷贝
fn1 = 'E:/test/a1.txt'fn2 = 'E:/test/a2.txt'with open(fn1,'w') as f: f.writelines('\n'.join(['abc','123','xyz']))with open(fn1,'rb') as f1: with open(fn2,'wb') as f2: length = 16*...
2019-07-05 16:38:22
165
原创 文件操作os,pathlib
import osfrom pathlib import Pathp = Path('E:/test/')print(list(p.glob('**/*'))) #返回当前目录下的所有内容递归print(os.listdir(p)) #返回当前目录下的所有内容不递归print(os.listdir('E:/test/')) #同上...
2019-07-04 20:29:08
128
原创 JS对象模型
要创建 Point 的新实例,必须使用 new 操作符。以这种方式调用构造函数实际上会经历以下 4个步骤:(1) 创建一个新对象;(2) 将构造函数的作用域赋给新对象(因此 this 就指向了这个新对象) ;(3) 执行构造函数中的代码(为这个新对象添加属性) ;(4) 返回新对象。老语法function Point (x,y) { // console.log('Poin...
2019-07-01 22:04:14
156
原创 JS函数
递归函数JS里面:const sum = function fn(n){ return n===0 ? 0: n + fn(--n)}console.log(sum(2))Python里面:def foo1(n): # if n == 0: # return 0 # else: # return n + foo1(n-1)...
2019-07-01 19:20:28
106
原创 JS语法
语句块function hello() { let a = 1; var b = 2; c = 3}if (true) { let d = 4; var e = 5; f = 6 if (1) { console.log(d) console.log(e) console.log(f)...
2019-06-30 23:48:12
75
原创 js++--简单运算
let d = --i - i-- - i-- - i // d=-1 i=-1 d=0 i=-2 d= 2 i = -3 d=2+3 i=-3console.log(d, i)let e = ++i + i++ + i++ + i// e= 1 i=1 e=2 i=2 ...
2019-06-29 21:22:11
631
原创 ORM具体操作
import sqlalchemy, enumfrom sqlalchemy import create_engine, Column, Integer, String, Date, ForeignKey, Enum, and_from sqlalchemy.orm import sessionmaker, relationshipfrom sqlalchemy.ext.declarativ...
2019-06-29 16:35:03
187
1
原创 元编程
简单理解:class Meta(type): #type是元类,创建类的类 Meta继承自type,就具备了创造类的功能 def __new__(cls, *args, **kwargs): print(cls) print(args) print(kwargs) name, _, attr = args ...
2019-06-29 13:19:34
173
原创 动态规划
求最大子串a = 'xxxxabcd'b = 'abcd'def foo1(a, b): length_a = len(a) length_b = len(b) matrix = [[0]*length_a for _ in range(length_b)] xmax = 0 xindex = 0 for i, x in enumerate(b...
2019-06-27 19:08:35
105
原创 re模块
import re# 取出字符串string8中所有的天气状态string8 = "{ymd:'2018-01-01',tianqi:'晴',aqiInfo:'轻度污染'}," \ "{ymd:'2018-01-02',tianqi:'阴~小雨',aqiInfo:'优'}," \ "{ymd:'2018-01-03',tianqi:'小雨~中雨',aqi...
2019-06-27 09:16:26
82
原创 pymsql事物管理
1,conn 建立连接2,cursor 建立游标3,ping测试4,建立查询语句5,cursor.execute 执行import pymysqlfrom pymysql.cursors import DictCursorconn = pymysql.connect('192.168.106.128', 'xinzhu', '123456', 'test')cursor = co...
2019-06-26 21:22:41
101
原创 定义外键约束
定义外键约束:from sqlalchemy import ForeignKey例如:emp_no = Column(Integer, ForeignKey('employees.emp_no', ondelete='CASCADE'), primary_key=True)
2019-06-26 18:05:24
2064
原创 ORM(object relational mapping)
对象关系映射(英语:(Object Relational Mapping,简称ORM))from sqlalchemy import Column, Integer, String, Date, Enum, and_, or_, not_, ForeignKey, create_enginefrom sqlalchemy.ext.declarative import declarative_b...
2019-06-25 15:26:04
147
原创 sql语句
sql语句选择:select * from table1 where 范围插入:insert into table1(field1,field2) values(value1,value2)删除:delete from table1 where 范围更新:update table1 set field1=value1 where 范围查找:select * from table1 whe...
2019-06-24 09:42:17
145
原创 asyncio实现echo服务端
asyncio实现echo服务端async def handle(reader:StreamReader, writer:StreamWriter): while True: writers = [] data = await reader.read(1024) if not data or data == b'quit': ...
2019-06-23 10:51:56
490
原创 selector群聊最终版
selector群聊最终版class A: def __init__(self, ip='127.0.0.1', port=9999): self.addr = ip, port self.sock = socket.socket() self.s = selectors.DefaultSelector() def start(s...
2019-06-19 17:19:39
131
原创 selectors进阶版
代码测试:class A: def __init__(self, ip='127.0.0.1', port=9999): self.addr = ip, port self.sock = socket.socket() self.s = selectors.DefaultSelector() def start(self): ...
2019-06-19 13:29:47
100
原创 selectors简陋版群聊
selectors简陋版群聊s = selectors.DefaultSelector()sock = socket.socket()sock.bind(('127.0.0.1', 9999))sock.listen()logger.info(sock)sock.setblocking(False)def accept(sock, mask): nwsock, ra...
2019-06-19 10:32:43
168
原创 ThreadingTCPServer
测试代码:import threadingfrom socketserver import StreamRequestHandler, ThreadingTCPServerclass A(StreamRequestHandler): clients = {} def setup(self): super().setup() self.cl...
2019-06-17 22:11:56
976
原创 udp客户端,过时删除
测试代码:import socketimport threadingimport datetimeclass A: def __init__(self, ip='127.0.0.1', port=9999, interval=10): self.addr = ip, port self.sock = socket.socket(type=socke...
2019-06-17 21:37:14
155
原创 socket编程
测试代码class A: def __init__(self, ip='127.0.0.1', port=9999): self.addr = ip, port self.sock = socket.socket() self.event = threading.Event() self.lock = threading.L...
2019-06-14 20:23:59
126
原创 osi参考模型对应协议
TCP/IP是网络上数据通信的一种协议,如果没有这个协议,你就在TCP/IP 网络上 什么也做不了HTTP协议是TCP/IP 协议里面包含的 应用层的协议而已,没有这个协议 只是 不能浏览网页而已,其他的服务是正常的 比如 邮件SMTP,POP3 协议,FTP等协议,这些协议都是 应用层协议TCP/IP协议里有链接层,网络层,传输层,应用层(HTTP协议就包含在应用层里的 一个协议)TCP/...
2019-06-14 19:03:50
1700
原创 logging模块
logging模块import loggingimport sysa = logging.getLogger('a') #get一个handlerprint(a.level) #初始的等级是0a.level = 20print(a.handlers)...
2019-06-11 22:28:43
92
原创 进程池和线程池的使用
进程池和线程池的使用from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutorimport loggingimport datetimeimport timeimport threadinga = '%(asctime)s %(message)s'logging.basicConfig(level=log...
2019-06-11 13:35:11
113
原创 多进程
多进程import multiprocessingimport loggingimport threadingimport datetimea = '%(asctime)s %(process)s %(processName)s %(threadName)s %(thread)8d %(message)s'logging.basicConfig(level=logging.INFO, ...
2019-06-10 23:04:00
70
原创 魔术方法__setattr__和__getattr__
__setattr____setattr__设置实例的属性存放在哪里,在调用时,在init方法之前例如:class A: d = {} def __init__(self,x,y): self.x = x self.y = y self.d['x'] = x self.d['y'] = y def __...
2019-05-26 20:32:03
196
原创 用类实现注册函数
例:def asd(): print('666')class A: def __init__(self): self.x = lambda :print('1') self.y = lambda :print('2') self.z = lambda :print('3') self.asd = asd...
2019-05-26 17:06:13
337
原创 上下文管理,调用call函数,装饰一个函数
上下文管理,调用call函数例:def add3(x,y): time.sleep(1) return x + yclass Timeit: def __init__(self,fn): self.fn = fn def __enter__(self): self.start = datetime.datetime.now(...
2019-05-26 11:34:46
77
原创 上下文管理,装饰一个函数
例:import datetimeimport timefrom functools import wraps,update_wrapperdef logger3(duration=3): def _logger3(fn): @wraps(fn) def inner(*args,**kwargs): start = dat...
2019-05-26 11:13:33
64
原创 函数,装饰一个函数
装饰器例:import datetimeimport timedef logger3(duration=3): def _logger3(fn): def inner(*args,**kwargs): start = datetime.datetime.now() ret = fn(*args,**kwargs) ...
2019-05-26 10:56:39
57
原创 类,装饰一个函数
类装饰器例:import datetimeimport timefrom functools import update_wrapperclass Logger3: '''this is logger3''' def __init__(self,fn): self.fn = fn update_wrapper(self,fn) ...
2019-05-26 10:46:38
107
原创 特殊属性dir()
魔术方法`__dir__`实例化一个类,dir(?),会显示什么?__dir__import导入什么当前模块dir()里面就添加进什么(见例1)dir()收集类的所有属性,包括继承类(祖先类)见例2例1:class A: def __init__(self): self.a = 5print('in 01',dir())a = A()from zs0...
2019-05-22 23:35:02
202
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人