04 2018 档案

摘要:#aio 爬虫,去重,入库 import asyncio import aiohttp import aiomysql import re from pyquery import PyQuery stoping = False start_url = 'http://www.jobbole.com/' waiting_urls = [] seen_urls = set() # url去重 -... 阅读全文
posted @ 2018-04-25 08:10 Erick-LONG 阅读(422) 评论(0) 推荐(0)
摘要:# # total = 0 # # async def add(): # #1. dosomething1 # #2. io操作 # # 1. dosomething3 # global total # for i in range(1000000): # total += 1 # async def desc(): # glo... 阅读全文
posted @ 2018-04-25 07:16 Erick-LONG 阅读(244) 评论(0) 推荐(0)
摘要:#asyncio 没有提供http协议的接口 aiohttp import asyncio import socket from urllib.parse import urlparse async def get_url(url): #通过socket请求html url = urlparse(url) host = url.netloc path = ur... 阅读全文
posted @ 2018-04-24 22:11 Erick-LONG 阅读(146) 评论(0) 推荐(0)
摘要:#使用多线程:在协程中集成阻塞io import asyncio from concurrent.futures import ThreadPoolExecutor import socket from urllib.parse import urlparse def get_url(url): #通过socket请求html url = urlparse(url) ... 阅读全文
posted @ 2018-04-24 21:49 Erick-LONG 阅读(457) 评论(0) 推荐(0)
摘要:event_loop 事件循环:程序开启一个无限循环,把一些函数注册到事件循环上,当满足事件发生的时候,调用相应的协程函数 coroutine 协程:协程对象,指一个使用async关键字定义的函数,它的调用不会立即执行函数,而是会返回一个协程对象。协程对象需要注册到事件循环,由事件循环调用。 tas 阅读全文
posted @ 2018-04-24 17:46 Erick-LONG 阅读(256) 评论(0) 推荐(0)
摘要:#python为了将语义变得更加明确,就引入了async和await关键词用于定义原生的协程 # async def downloader(url): # return "xxxx" import types @types.coroutine def downloader(url): yield "xxx" async def download_url(url): #... 阅读全文
posted @ 2018-04-24 14:31 Erick-LONG 阅读(275) 评论(0) 推荐(0)
摘要:#1. epoll并不代表一定比select好 # 在并发高的情况下,连接活跃度不是很高, epoll比select # 并发性不高,同时连接很活跃, select比epoll好 #通过非阻塞io实现http请求 # select + 回调 + 事件循环 # 并发性高 # 使用单线程 import socket from urllib.parse import urlparse from ... 阅读全文
posted @ 2018-04-24 07:35 Erick-LONG 阅读(1260) 评论(0) 推荐(0)
摘要:import time from multiprocessing import Process, Queue, Pool, Manager, Pipe # def producer(queue): # queue.put("a") # time.sleep(2) # # def consumer(queue): # time.sleep(2) # data =... 阅读全文
posted @ 2018-04-23 23:01 Erick-LONG 阅读(154) 评论(0) 推荐(0)
摘要:# import os # #fork只能用于linux/unix中 # pid = os.fork() # print("bobby") # if pid == 0: # print('子进程 {} ,父进程是: {}.' .format(os.getpid(), os.getppid())) # else: # print('我是父进程:{}.'.format(pid)) imp... 阅读全文
posted @ 2018-04-23 22:49 Erick-LONG 阅读(136) 评论(0) 推荐(0)
摘要:多进程 阅读全文
posted @ 2018-04-23 16:29 Erick-LONG 阅读(413) 评论(0) 推荐(0)
摘要:线程间通信 -Queue 线程锁,lock和Rlock 条件变量-线程间同步 Semaphore 是用于控制进入数量的锁 阅读全文
posted @ 2018-04-23 08:00 Erick-LONG 阅读(286) 评论(0) 推荐(0)
摘要:#500G, 特殊 一行 def myreadlines(f, newline): buf = "" while True: while newline in buf: pos = buf.index(newline) yield buf[:pos] buf = buf[pos + len(newline):] chunk = f.re... 阅读全文
posted @ 2018-04-23 06:51 Erick-LONG 阅读(122) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2018-04-22 20:39 Erick-LONG 阅读(251) 评论(0) 推荐(0)
摘要:import requests,time from lxml import etree import win32api,win32con import winsound import pyttsx3 cookies = str(input('请输入cookies:')) def ring(): engine = pyttsx3.init() engine.say('傻逼,有户... 阅读全文
posted @ 2018-04-20 14:23 Erick-LONG 阅读(410) 评论(0) 推荐(0)
摘要:#什么是迭代协议 #迭代器是什么? 迭代器是访问集合内元素的一种方式, 一般用来遍历数据 #迭代器和以下标的访问方式不一样, 迭代器是不能返回的, 迭代器提供了一种惰性方式数据的方式 #[] list , __iter__ from collections.abc import Iterable, Iterator a = [1,2] iter_rator = iter(a) print (i... 阅读全文
posted @ 2018-04-19 17:13 Erick-LONG 阅读(155) 评论(0) 推荐(0)
摘要:# 需求 import numbers class Field: pass class IntField(Field): # 数据描述符 def __init__(self, db_column, min_value=None, max_value=None): self._value = None self.min_value = ... 阅读全文
posted @ 2018-04-19 16:56 Erick-LONG 阅读(304) 评论(0) 推荐(0)
摘要:#类也是对象,type创建类的类 def create_class(name): if name == "user": class User: def __str__(self): return "user" return User elif name == "company": ... 阅读全文
posted @ 2018-04-19 15:55 Erick-LONG 阅读(135) 评论(0) 推荐(0)
摘要:class User: def __new__(cls, *args, **kwargs): print (" in new ") return super().__new__(cls) def __init__(self, name): print (" in init") pass a = int() #new ... 阅读全文
posted @ 2018-04-19 15:05 Erick-LONG 阅读(186) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2018-04-19 08:09 Erick-LONG 阅读(176) 评论(0) 推荐(0)
摘要:from datetime import date, datetime import numbers class IntField: #数据描述符,实现以下任意一个,都会变为属性描述符 def __get__(self, instance, owner): return self.value def __set__(self, instance, val... 阅读全文
posted @ 2018-04-18 18:51 Erick-LONG 阅读(210) 评论(0) 推荐(0)
摘要:#__getattr__, __getattribute__ #__getattr__ 就是在查找不到属性的时候调用 from datetime import date class User: def __init__(self,info={}): self.info = info def __getattr__(self, item): ret... 阅读全文
posted @ 2018-04-18 18:09 Erick-LONG 阅读(177) 评论(0) 推荐(0)
摘要:from datetime import date, datetime class User: def __init__(self, name, birthday): self.name = name self.birthday = birthday self._age = 0 # def get_age(self): #... 阅读全文
posted @ 2018-04-18 17:18 Erick-LONG 阅读(126) 评论(0) 推荐(0)
摘要:编写 __enter__ 和 __exit__ 仍然很繁琐,因此Python的标准库 contextlib 提供了更简单的写法 @contextmanager 这个装饰器接受一个 generator,用 yield 语句把 with ... as var 把变量输出出去,然后,with 语句就可以正 阅读全文
posted @ 2018-04-17 18:18 Erick-LONG 阅读(181) 评论(0) 推荐(0)
摘要:mixin模式特点: 1、单一功能, 2、不和基类关联,可以和任意基类组合,基类可以不和mixin关联就可以初始化成功 3、不使用 super() 用法 阅读全文
posted @ 2018-04-17 17:53 Erick-LONG 阅读(233) 评论(0) 推荐(0)
摘要:在Flask内部使用两张表维护路由: url_map :维护URL规则和endpoint的映射 view_functions :维护endpoint和视图函数的映射。 以用户访问URL/home为例,Flask将首先利用url_map找到所请求URL对应的 endpoint,即访问点home,然后再 阅读全文
posted @ 2018-04-16 22:47 Erick-LONG 阅读(309) 评论(0) 推荐(0)
摘要:转载自https://blog.csdn.net/The_One_is_all/article/details/76063968 基本环境: Ubuntu 16.10 docker 17.06.0-ce 压缩自己的项目文件 1.这里需要注意的是,在压缩的时候,也需要把自己的需要的Python包写在r 阅读全文
posted @ 2018-04-13 10:37 Erick-LONG 阅读(1727) 评论(0) 推荐(0)
摘要:转载自 https://segmentfault.com/a/1190000012921606 环境 阿里云ESC,宿主机服务器安装Docker,在安全规则中确认8080端口开启。 客户端mac 运行jenkins 运行jenkins容器 在主机上创建目录,并添加读写权限以便jenkins应用运行时 阅读全文
posted @ 2018-04-13 10:28 Erick-LONG 阅读(23699) 评论(0) 推荐(0)
摘要:关闭jenkins服务:http://localhost:8080/exit 将上面的exit改为restart后就可以重新启动jenkins服务器。http://localhost:8080/restart 重新加载配置信息。http://localhost:8080/reload 阅读全文
posted @ 2018-04-13 10:24 Erick-LONG 阅读(171) 评论(0) 推荐(0)
摘要:入门 首先使用pip安装Pipenv及其依赖项, 1 然后将目录更改为包含你的Python项目的文件夹,并启动Pipenv, 1 2 这将在项目目录中创建两个新文件Pipfile和Pipfile.lock,如果项目不存在,则为项目创建一个新的虚拟环境。 如果你添加–two或–three标志到上面的最 阅读全文
posted @ 2018-04-12 09:51 Erick-LONG 阅读(281) 评论(0) 推荐(0)
摘要:pymongo来操作MongoDB数据库,但是直接把对于数据库的操作代码都写在脚本中,这会让应用的代码耦合性太强,而且不利于代码的优化管理 一般应用都是使用MVC框架来设计的,为了更好地维持MVC结构,需要把数据库操作部分作为model抽离出来,这就需要借助MongoEngine MongoEngi 阅读全文
posted @ 2018-04-09 18:32 Erick-LONG 阅读(308) 评论(0) 推荐(0)
摘要:第1章 课程介绍 ①界面中左右最边上的小窗口(旋转了90度的字体)都自带了下标,win下快捷键alt+index切换窗口 ②演示效果:模拟时钟,快捷键如,0到100的for循环:100.fori;输出:sout;Thread.sleep()等... 第2章 高效定位代码 ①快速切换文件,类等(rec 阅读全文
posted @ 2018-04-09 13:22 Erick-LONG 阅读(1438) 评论(0) 推荐(0)