01 2019 档案
python pandas使用chunksize异步拆分固定行数的文件
摘要:import pandas as pd import asyncio from collections import defaultdict collect = defaultdict(list) #######创建处理一个对象的方法,并返回期物 async def dealone(chunk,sas): path='/data/chaifen/testphone_%d.txt'%sas... 阅读全文
posted @ 2019-01-14 18:12 hailuo 阅读(3588) 评论(0) 推荐(0) 编辑
python3.5+ asyncio await异步详解
摘要:import asyncio,time from collections import defaultdict from pprint import pprint collect=defaultdict(list) #######创建处理一个对象的方法,并返回期物 async def dealone(chunk): return 'Receive %d at %.5f seconds' %... 阅读全文
posted @ 2019-01-11 10:09 hailuo 阅读(815) 评论(0) 推荐(0) 编辑
python 使用缓存加快运算
摘要:from functools import lru_cache import time from functools import wraps def clock(func): @wraps(func) def clocked(*args, **kwargs): t0 = time.time() r 阅读全文
posted @ 2019-01-08 14:38 hailuo 阅读(422) 评论(0) 推荐(0) 编辑
python fileinput处理多文件
摘要:import fileinput with fileinput.input(files=(path1,path2)) as f: for line in f: print(line) 阅读全文
posted @ 2019-01-08 10:59 hailuo 阅读(316) 评论(0) 推荐(0) 编辑
python any和all
摘要:摘自《流畅的Python》 all 和 any 也是内置的归约函数。 all(iterable) 如果 iterable 的每个元素都是真值,返回 True;all([]) 返回 True。 any(iterable) 只要 iterable 中有元素是真值,就返回 True;any([]) 返回 阅读全文
posted @ 2019-01-04 14:16 hailuo 阅读(232) 评论(0) 推荐(0) 编辑
python pandas使用一些协程
摘要:import pandas as pd def coroutine(func): """装饰器:向前执行到第一个`yield`表达式,预激`func`""" @wraps(func) def primer(*args,**kwargs): gen = func(*args,**kwargs) next(gen) return gen primer.__name__ = fu... 阅读全文
posted @ 2019-01-02 17:27 hailuo 阅读(643) 评论(0) 推荐(0) 编辑
Python 实现flatten功能
摘要:from collections import Iterable def flatten(items): for x in items: if isinstance(x, Iterable) and not isinstance(x, (str, bytes)): yield from flatte 阅读全文
posted @ 2019-01-02 16:47 hailuo 阅读(1094) 评论(0) 推荐(0) 编辑
Python 自定义iterator生成器
摘要:#计数版 class countdown(object): def __init__(self,start): self.start = start def __iter__(self): return countdown_iter(self.start) class countdown_iter(object): def __init__(self, count): sel... 阅读全文
posted @ 2019-01-02 11:32 hailuo 阅读(424) 评论(0) 推荐(0) 编辑


点击右上角即可分享
微信分享提示