- 博客(34)
- 收藏
- 关注
原创 asyncio
node2:/root/python/20200525#cat t900.py import asyncioimport aiohttpimport timeasync def download_one(url): async with aiohttp.ClientSession() as session: async with session.get(url) as resp: print('Read {} from {}'.format(r..
2020-05-29 17:00:47 126
原创 python 多线程 多进程
node2:/root/python/20200525#cat t600.py import requestsimport timedef download_one(url): resp = requests.get(url) print('Read {} from {}'.format(len(resp.content), url)) def download_all(sites): for site in sites: download_...
2020-05-29 15:57:23 206
原创 3.在url中传递参数(其实与requests模块使用大致相同)
3.在url中传递参数(其实与requests模块使用大致相同)node2:/root/python/20200525#cat t500.py import asyncio,aiohttpasync def fetch_async(url,params): async with aiohttp.ClientSession() as session: async with session.get(url,params=params) as r: pr.
2020-05-26 21:14:45 313
原创 POST 请求数据
post 请求数据:# !/usr/bin/env python# -*- coding: utf-8 -*-import requestsimport osimport timemyurl='http://192.168.137.3:9000/test111/'print myurls=requests.session()data={'a':'1111','b':'222'}#res = requests.post(myurl, data=data)res = requests.
2020-05-26 21:10:48 343
原创 django get请求获取请求参数
get请求参数:#@require_http_methods(["POST"])def test111(req): #time.sleep(5) a=req.GET['a'] print a b=req.GET['b'] print b return HttpResponse(str(a)) # !/usr/bin/env python# -*- coding: utf-8 -*-import requestsimport osimpor.
2020-05-26 20:49:38 1420
原创 3.除了上面的get方法外,会话还支持post,put,delete....等
3.除了上面的get方法外,会话还支持post,put,delete....等session.put('http://httpbin.org/put', data=b'data')session.delete('http://httpbin.org/delete')session.head('http://httpbin.org/get')session.options('http://httpbin.org/get')session.patch('http://httpbin.org/pat.
2020-05-26 14:08:00 198
原创 2.发起一个session请求
2.发起一个session请求node2:/root/python/20200525#cat t300.py import asyncio,aiohttp# -*- coding: utf-8 -*-async def fetch_async(url): print(url) async with aiohttp.ClientSession() as session:#协程嵌套,只需要处理最外层协程即可fetch_async async with sessio.
2020-05-26 11:36:36 212
原创 1.aiohttp的简单使用(配合asyncio模块)
1.aiohttp的简单使用(配合asyncio模块)def test111(req): time.sleep(5) return HttpResponse('test111 success')def test222(req): time.sleep(6) return HttpResponse('test222 success')def test333(req): time.sleep(7) return HttpResponse('test33.
2020-05-26 11:26:40 367
原创 django.middleware.cache.FetchFromCacheMiddleware 全局缓存坑
使用中间件,经过一系列的认证等操作,如果内容在缓存中存在,则使用FetchFromCacheMiddleware获取内容并返回给用户,当返回给用户之前,判断缓存中是否已经存在,如果不存在则UpdateCacheMiddleware会将缓存保存至缓存,从而实现全站缓存 MIDDLEWARE = [ 'django.middleware.cache.UpdateCacheMiddleware', # 其他中间件... 'django.middlewar.
2020-05-25 20:44:26 371
原创 python 3.7 协程
协程:协程是实现并发编程的一种方式。一说并发,你肯定想到了多线程 / 多进程模型,没错,多线程 / 多进程node2:/root/python/20200524#cat t1.py import timedef crawl_page(url): print('crawling {}'.format(url)) sleep_time = int(url.split('_')[-1]) time.sleep(sleep_time) print('OK {}'...
2020-05-24 11:01:15 248
原创 闭包 返回函数对象
第四点,要知道,函数的返回值也可以是函数对象(闭包),比如下面这个例子:def func_closure(): def get_message(message): print '11111111111111111111111111111' print('Got a message: {}'.format(message)) return get_messagesend_message = func_closure()print send_mes..
2020-05-17 21:19:33 353
原创 python 函数导入
简单模块化说到最简单的模块化方式,你可以把函数、类、常量拆分到不同的文件,把它们放在同一个文件夹,然后使用 from your_file import function_name, class_name 的方式调用。之后,这些函数和类就可以在文件内直接使用了。node2:/root/python#cat utils.pydef get_sum(a, b): return a + bnode2:/root/python#cat class_utils.py# class_util.
2020-05-16 20:26:32 323
原创 调用父类和子类的__init__方法
class SearchEngineBase(object): def __init__(self): print '111111'class SimpleEngine(SearchEngineBase): def __init__(self): print '222222222' # super(SimpleEngine, self).__init__() # self.__id_to_texts = {}x=Sim.
2020-05-15 14:51:02 702
原创 __init__构造函数
# -*- coding: utf-8 -*-class Document(): def __init__(self, title, author, context): print('init function called') self.name='xxx'harry_potter_book = Document('Harry Potter', 'J. K. Rowling', '... Forever Do not believe any thing is cap.
2020-05-14 21:54:04 313
原创 面向对象例子
class SearchEngineBase(object): def __init__(self): pass def add_corpus(self, file_path): with open(file_path, 'r') as fin: text = fin.read() self.process_corpus(file_path, text) def process_corpus(self, ..
2020-05-10 20:59:58 186
原创 super()调用父类方法
详解python的super()的作用和原理:Python 中对象的定义很怪异,第一个参数一般都命名为self,用于传递对象本本身,而在调用的时候则不必显示传递,系统会自动传递今天我们介绍的主角是super(),在类的继承里面super()非常常用,它解决了子类调用父类方法的一些问题,父类多次被调用只执行一次。当存在继承关系的时候,有时候需要在子类中调用父类的方法此时最简单的方法是把对象调用转换成类调用,需要注意的是这时self参数需要显示传递class FooPare..
2020-05-10 20:31:11 1321
原创 如何在一个类中定义一些常量,每个对象都可以方便访问这些常量而不用重新构造?
如何在一个类中定义一些常量,每个对象都可以方便访问这些常量而不用重新构造?class Document(): WELCOME_STR = 'Welcome! The context for this book is {}.'a=Document()print type(a)print dir(a)print a.WELCOME_STRC:\Python27\python.exe "C:/Users/TLCB/PycharmProjects/untitled2/python stud.
2020-05-10 17:22:11 423
原创 __init__函数一定需要吗
其中,init 表示构造函数,意即一个对象生成时会被自动调用的函数没有init构造函数呢?class Document(): # def __init__(self): # pass def fun1(self,a): return aharry_potter_book = Document()print type(harry_potter_book)print dir(harry_potter_book)print harry_pott.
2020-05-10 16:53:00 1120
原创 python 面向对象编程
node2:/root/python/object#cat fa.pyclass SearchEngineBase(object): def main(self,a): return anode2:/root/python/object#cat ch.py from fa import SearchEngineBaseclass SimpleEngine(SearchEngineBase): def __init__(self): passx= SimpleE..
2020-05-10 16:35:49 142 1
原创 jvm 诊断工具
#!/bin/bash# @Function# Find out the highest cpu consumed threads of java, and print the stack of these threads.## @Usage# $ ./show-busy-java-threads## @online-doc https://github.com/oldratlee/useful-scripts/blob/master/docs/java.md#-show-busy-ja.
2020-05-09 16:15:35 299
原创 shell 输出到数组
top_cmd_line=(top -H -b -d 0.5 -n 2)top_out=$(${top_cmd_line[@]})echo $top_out
2020-05-09 14:30:42 1881
原创 类 对象 属性 函数
参照着这段代码,我先来简单解释几个概念。类:一群有着相似性的事物的集合,这里对应 Python 的 class。对象:集合中的一个事物,这里对应由 class 生成的某一个 object,比如代码中的 harry_potter_book。属性:对象的某个静态特征,比如上述代码中的 title、author 和 __context。函数:对象的某个动态能力,比如上述代码中的 inte...
2020-05-07 20:41:36 229
原创 python 继承
继承:class Entity(): # def __init__(self, object_type): # print('parent class init called') # self.object_type = object_type def get_context_length(self): raise Except...
2020-05-07 20:13:10 241
原创 成员函数和类函数
类函数;# -*- coding:utf-8 -*-# !/usr/bin/pythonclass Document(): def __init__(self, title, author, context): print('init function called') self.title = title self.author = autho...
2020-05-07 20:03:56 371
原创 python 实例属性和类属性
如何在一个类中定义一些常量,每个对象都可以方便访问这些常量而不用重新构造?第一个问题,在 Python 的类里,你只需要和函数并列地声明并赋值,就可以实现这一点,例如这段代码中的 WELCOME_STR。一种很常规的做法,是用全大写来表示常量,因此我们可以在类中使用 self.WELCOME_STR ,或者在类外使用 Entity.WELCOME_STR ,来表达这个字符串。...
2020-05-07 19:55:53 193
原创 dump 叶子节点
Dump 叶子节点:----- begin tree dumpbranch: 0x1031b23 16980771 (0: nrow: 106, level: 2) branch: 0x10556b0 17127088 (-1: nrow: 414, level: 1) leaf: 0x1031b24 16980772 (-1: nrow: 363 rrow: 363)...
2020-05-07 15:03:14 277
原创 Dump 分支块
dump 分支块:----- begin tree dumpbranch: 0x1031b23 16980771 (0: nrow: 106, level: 2) branch: 0x10556b0 17127088 (-1: nrow: 414, level: 1) leaf: 0x1031b24 16980772 (-1: nrow: 363 rrow: 363) ...
2020-05-07 14:24:06 170
原创 oracle dump 根节点
2. B树索引的内部结构我们可以使用如下方式将B树索引转储成树状结构的形式而呈现出来:我们可以使用如下方式将B树索引转储成树状结构的形式而呈现出来:alter session set events 'immediate trace name treedump level INDEX_OBJECT_ID'; 比如,对于上面的例子来说,我们把创建在goodid上的名为idx_wa...
2020-05-07 11:44:43 216
原创 oracle 直接建索引锁表
重建索引锁表:Session 1:SQL> select * from v$mystat where rownum<2; SID STATISTIC# VALUE---------- ---------- ---------- 12 0 0Session 2:SQL> select * from v$myst...
2020-05-07 09:01:09 2015
原创 python 中的闭包
闭包这节课的第三个重点,我想再来介绍一下闭包(closure)。闭包其实和刚刚讲的嵌套函数类似,不同的是,这里外部函数返回的是一个函数,而不是一个具体的值。返回的函数通常赋于一个变量,这个变量可以在后面被继续执行调用。# -*- coding:utf-8 -*-# !/usr/bin/pythondef nth_power(exponent): def expone...
2020-05-06 19:03:00 166
原创 python 列表和元祖
count(item) 表示统计列表 / 元组中 item 出现的次数。l = [1, 2, 3, 4,'item',45,'item']print lprint l[0]l[3]=99print lprint l.count('item')index(item) 表示返回列表 / 元组中 item 第一次出现的索引。l = [1, 2, 3, 4,'item',45,'...
2020-05-05 20:32:00 186
原创 叶子节点包含rowid信息
然后,我们从中随便挑一个叶子节点,对其进行转储。假设就选row#0行所指向的叶子节点,根据dba的值: 25226402可以知道,文件号为6,数据块号为60578。将其转储以后,其内容如下所示,我只显示与分支节点不同的部分。 ----- begin tree dumpbranch: 0x103151b 16979227 (0: nrow: 7, level: 2) ...
2020-05-05 15:53:18 217
原创 Dump 分支块
drop table test;create table test(goodid char(8),OBJECT_NAME varchar(100));insert into test select a.object_id,a.object_name from warecountd aSQL> desc test;Name Type Null...
2020-05-05 12:53:46 172
原创 索引分支块结构
对于分支节点块(包括根节点块)来说,其所包含的索引条目都是按照顺序排列的(缺省是升序排列,也可以在创建索引时指定为降序排列)。每个索引条目(也可以叫做每条记录)都具有两个字段。第一个字段表示当前该分支节点块下面所链接的索引块中所包含的最小键值;第二个字段为四个字节,表示所链接的索引块的地址,该地址指向下面一个索引块。在一个分支节点块中所能容纳的记录行数由数据块大小以及索引键值的长度决定。比如从...
2020-05-05 09:50:19 348
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人