随笔分类 -  python

python 遍历hadoop, 跟指定列表对比 包含列表中值的取出。
摘要:import sysimport tstreefname = 'high_freq_site.list'tree = tstree.TernarySearchTrie()tree.loadData(fname)token = ''counter = 0post = []# url, count, p... 阅读全文

posted @ 2015-12-19 04:25 雨渐渐 阅读(746) 评论(0) 推荐(0) 编辑

python 基于小顶堆实现随机抽样
摘要:起因:之前用蓄水池抽样,算法精简,但直观性很差。 所以这次采用了简单的,为没一个行,赋值一个随机值,然后取 最大的K个作为,随机样本。基本思路:为每一个行(record,记录,实体) 赋一个random值。 每个map取一个Top K 值。 由于是求topk,可以设置一个reduce,再求 Top ... 阅读全文

posted @ 2015-11-11 13:58 雨渐渐 阅读(1040) 评论(0) 推荐(0) 编辑

python 行转列
摘要:#encoding=utf-8 print '中国' #二维阵列变换 行转化成列,列转化成行 lista=[[1,2,3],[4,5,6],[7,8,9],[10,11,12]] #使用列表推导 listb=[[r[col] for r in lista] for col in... 阅读全文

posted @ 2015-09-24 10:26 雨渐渐 阅读(8623) 评论(0) 推荐(0) 编辑

python logging TimedRotatingFileHandler 作用
摘要:max backup count这样的参数,即打印的日志文件数量超过这个阈值,发生rotate,从最老的文件开始清理未亲测。 阅读全文

posted @ 2015-09-14 15:57 雨渐渐 阅读(1149) 评论(0) 推荐(0) 编辑

python 安装 easy_intall 和 pip python无root权限安装
摘要:http://www.cnblogs.com/haython/p/3970426.htmleasy_install和pip都是用来下载安装Python一个公共资源库PyPI的相关资源包的首先安装easy_install下载地址:https://pypi.python.org/pypi/ez_setu... 阅读全文

posted @ 2015-07-10 13:48 雨渐渐 阅读(3969) 评论(0) 推荐(0) 编辑

待买书籍
摘要:http://item.jd.com/11666319.html 贝叶斯思维 阅读全文

posted @ 2015-06-10 14:24 雨渐渐 阅读(106) 评论(0) 推荐(0) 编辑

无root权限安装python
摘要:http://lujialong.com/?p=150pipe 安装第三方包http://www.lfd.uci.edu/~gohlke/pythonlibs/#piphttp://www.cnblogs.com/ShepherdIsland/p/4239052.html最近在刚分的主机操作,发现p... 阅读全文

posted @ 2015-06-08 20:54 雨渐渐 阅读(2035) 评论(0) 推荐(0) 编辑

python 发邮件 utf-8
摘要:import smtplibfrom operator import itemgetter, attrgetterfrom email.mime.text import MIMETextfrom email.header import Headerfrom email.mime.multipart ... 阅读全文

posted @ 2015-06-05 19:09 雨渐渐 阅读(490) 评论(0) 推荐(0) 编辑

python 函数默认值的小坑啊
摘要:import datetimeimport timedef test(day=datetime.datetime.now()): print daywhile True: test() time.sleep(1)run result:2015-06-05 16:52:47.106... 阅读全文

posted @ 2015-06-05 16:55 雨渐渐 阅读(147) 评论(0) 推荐(0) 编辑

python 日期转星期
摘要:import timeimport datetimetoday = int(time.strftime('%w'))print todayanyday = datetime.datetime(2012, 04, 22).strftime('%w')print anyday 阅读全文

posted @ 2015-06-03 10:36 雨渐渐 阅读(1023) 评论(0) 推荐(0) 编辑

python 处理cookie简单很多啊 httpclient版本是4.3.3
摘要:模拟登录流程:1 请求host_url2 从host_url中解析出 隐藏表单 的值 添加到POST_DATA中3 添加账户,密码到POST_DATA中4 编码后,发送POST请求 要点1:java下,HttpClient必须是单例模式 要点2:post的url可能跟登录界面的url不同。post_... 阅读全文

posted @ 2014-06-05 18:38 雨渐渐 阅读(1693) 评论(0) 推荐(0) 编辑

python 教程
摘要:http://www.w3cschool.cc/python/func-number-sqrt.html 阅读全文

posted @ 2014-05-07 09:27 雨渐渐 阅读(148) 评论(0) 推荐(0) 编辑

matplotlib 显示中文
摘要:# --*-- coding: utf-8 --*--from matplotlib.font_manager import FontPropertiesimport matplotlib.pyplot as pltfont = FontProperties(fname=r"/usr/share/f... 阅读全文

posted @ 2014-05-05 13:48 雨渐渐 阅读(523) 评论(0) 推荐(0) 编辑

一个奇怪的编码 big5-hkscs
摘要:# --*-- coding:utf-8 --*--import urllib2import urllibpostDict = { 'IsExist_Slt_Part_Id': 'False', 'IsExist_Slt_Stock_Id': 'False', 'current_p... 阅读全文

posted @ 2014-05-04 17:48 雨渐渐 阅读(737) 评论(0) 推荐(0) 编辑

python 重载 __hash__ __eq__
摘要:__author__ = 'root'from urlparse import urlparseclass host_news(): def __init__(self, id, url): self.id = id urlinfo = urlparse(url) ... 阅读全文

posted @ 2014-05-04 15:59 雨渐渐 阅读(1056) 评论(0) 推荐(0) 编辑

python 一致性hash
摘要:https://pypi.python.org/pypi/hash_ring/一致性 哈希 自己玩下 试试 阅读全文

posted @ 2014-05-04 15:43 雨渐渐 阅读(148) 评论(0) 推荐(0) 编辑

python is == 的区别
摘要:要点: is 判断是否是同一个对象。是通过id来判断的 == 是通过值来判断的 为了提高内存利用率对一些简单的对象,如一些数值较小的int对象,python采用重用对象内存的方法例如指向a=2,b=2时,由于2作为简单的int类型且数值小,python不会两次为其分配内存,而是只分配一次,然后... 阅读全文

posted @ 2014-05-04 14:34 雨渐渐 阅读(267) 评论(0) 推荐(0) 编辑

python 遍历字典
摘要:dict={"a":"apple","b":"banana","o":"orange"} print "##########dict######################" for i in dict: print "dict[%s]=" % i,dict[i] print... 阅读全文

posted @ 2014-05-04 11:45 雨渐渐 阅读(283) 评论(0) 推荐(0) 编辑

python多线程 批量下补丁
摘要:一个一个下载 要2个多小时。就直接起了个线程池。效果明显。import urllib2from urlparse import urlparseuri = 'http://******/patch****'d = urllib2.urlopen(uri)res = urlparse(uri)f = ... 阅读全文

posted @ 2014-05-03 14:18 雨渐渐 阅读(226) 评论(0) 推荐(0) 编辑

python url解析
摘要:>>> url="http://localhost/test.py?a=hello&b=world " >>> result=urlparse.urlparse(url) >>> result ParseResult(scheme='http', netloc=... 阅读全文

posted @ 2014-04-29 15:19 雨渐渐 阅读(337) 评论(0) 推荐(0) 编辑

导航