03 2013 档案

python 中需要养成的便捷方法
摘要:1,tuple 的多赋值 (a,b,c) = c,d,e2,ls = [i for i in range(10)] str = ["%s = %s" %(key ,value ) for key, value in ]3,getattr() 函数,ex:getattr([],'pop')4,可以使用 ["%s"%format]来做字符串的替换。5,lambda 函数没有 函数名字6,and-or 技巧 可以 充当c中的 bool?a:b ex:1 a = "a"2 b = "b"3 1 and a 阅读全文

posted @ 2013-03-26 23:10 Harveyaot 阅读(161) 评论(0) 推荐(0) 编辑

python 继承中的一个super使用
摘要:1 class C(P):2 def __init__(self):3 super(C,self).__init__()4 print "calling C's constructor!"在这个继承的例子中,不会因为调用了子类的__init__()方法,而自动调用父类的该方法,必须明确的调用,否则无效,和java差距很大。super方法,比直接使用P.__init__()要灵活,经来代码改动较少 阅读全文

posted @ 2013-03-26 15:10 Harveyaot 阅读(111) 评论(0) 推荐(0) 编辑

xpath 取 所有的属性值
摘要:是etree.xpath('//@href")能取出该页所有的链接值 阅读全文

posted @ 2013-03-26 10:02 Harveyaot 阅读(663) 评论(0) 推荐(0) 编辑

python 中文乱码
摘要:1,print 函数打印时,乱码的处理就交给了,os来做,只负责发送字符串给它。?(看来不是,因为python 在print 时自动读取。sys.stdout.encoding 属性值,自动进行编码)还有,utf-8 和 gkb等等之间相互转换,只需python 存贮了各自的编码规则,按照该规则编码,解码都可以,不是什么大事,麻烦事,只是转的时候,ascii 范围很小,发现很多字符没有对应,所以会抛出错误。python 中字符串,分为两种,一种是unicode的s=u'哈哈',另外一种是 s = '哈哈',该种已经按照python encoding 的属性,进行 阅读全文

posted @ 2013-03-25 11:45 Harveyaot 阅读(741) 评论(0) 推荐(0) 编辑

关于python的lxml.html 的fromstring 函数
摘要:1,使用html.fromString 函数的话,感觉不像是先解析成dom树的,所以无论给的文档是什么,it can always deal it.Sometimes,I delete all the titel , body and html tag,It doesn't matter actually.2,html.fromstring 会解析html 头部中charset属性,并且自动的decode3,它只看start 标签,根据正则定位到该字符串出现的位置,然后开始寻找xpath 中下一个路径,所以开始的标签很重要。 阅读全文

posted @ 2013-03-25 11:10 Harveyaot 阅读(7430) 评论(0) 推荐(0) 编辑

python string 到date object
摘要:string 到date object:1 datetime.datetime.strptime("2013-03-18 09:00","%Y-%m-%d %H:%M")date之间的比较: 存在datetime下的timedelta类delta = datetime.timedelta(days,seconds,totalseconds)d1 = datetime.datetime(year,month,day,hour,minute,second)d2 =datetime.datetime(year,month,day,hour,minute,sec 阅读全文

posted @ 2013-03-22 16:49 Harveyaot 阅读(226) 评论(0) 推荐(0) 编辑

python变量作用域
摘要:1 def test():2 c = 13 print a,b4 print c5 6 if __name__ == "__main__":7 a = 1;8 b = 2;9 test() test函数中的,a,b依然可以声明成功,并且成功打印结果,说明在编译时,并不检查函数的值是否已经声 阅读全文

posted @ 2013-03-22 15:40 Harveyaot 阅读(117) 评论(0) 推荐(0) 编辑

如何改变mysql auto increment 步长和初始值
摘要:auto_increment_incrementcontrols the interval between successive column values. For example:mysql> SHOW VARIABLES LIKE 'auto_inc%';+--------------------------+-------+| Variable_name | Value |+--------------------------+-------+| auto_increment_increment | 1 || auto_increment_offset ... 阅读全文

posted @ 2013-03-22 14:39 Harveyaot 阅读(766) 评论(0) 推荐(0) 编辑

python mysql 连接数据库 latin-1 codec错误
摘要:需要设置 charset 值,否则默认为latin 编码。con = mdb.connect('HOST', 'usr','passwd', 'table',charset="utf8");设置之后为utf-8,有的机器会出现 initialize charset error.可以挑战utf-8 为 utf,问题解决,utf-8和utf8在mysql中不可兼用。 阅读全文

posted @ 2013-03-21 13:20 Harveyaot 阅读(213) 评论(0) 推荐(0) 编辑

python + lxml 解析静态网页
摘要:1, firefox 下可以使用 firepath 插件 寻找到每个属性的xpath2,感觉xpath 非常好用,简单,适合取网页中结构化的数据 1 import sys 2 import lxml.html as HTML 3 4 file=sys.argv[1] 5 doc = HTML.fromstring(open(file).read()) 6 7 table = doc.xpath(".//*[@id='infoTable']/tbody/tr") 8 for i in range(1,len(table)): 9 tr = table[i]10 阅读全文

posted @ 2013-03-19 15:48 Harveyaot 阅读(367) 评论(0) 推荐(0) 编辑

python 使用 mysqldb 批量插入数据
摘要:转自 longriver.me下面来大致演示一下插入数据,批量插入数据,更新数据的例子吧:import MySQLdb try: conn=MySQLdb.connect(host='localhost',user='root',passwd='root',port=3306) cur=conn.cursor() cur.execute('create database if not exists python') conn.select_db('python') cur.execute('create t 阅读全文

posted @ 2013-03-19 15:31 Harveyaot 阅读(8140) 评论(0) 推荐(1) 编辑

Mysql 相似数据类型区别
摘要:1,INTEGER,INT,SMALLINT,TINYINT,MEDIUMINT,BIGINTTypeStorageMinimum ValueMaximum Value(Bytes)(Signed/Unsigned)Signed/Unsigned)TINYINT1-1281270255SMALLINT2-3276832767065535MEDIUMINT3-83886088388607016777215INT4-2147483648214748364704294967295BIGINT8-92233720368547758089223372036854775807018446744073709 阅读全文

posted @ 2013-03-19 13:40 Harveyaot 阅读(239) 评论(0) 推荐(0) 编辑

怎样量化评价搜索引擎的结果质量
摘要:搜索质量评估是搜索技术研究的基础性工作,也是核心工作之一。评价(Metrics)在搜索技术研发中扮演着重要角色,以至于任何一种新方法与他们的评价方式是融为一体的。搜索引擎结果的好坏与否,体现在业界所称的在相关性(Relevance)上。相关性的定义包括狭义和广义两方面,狭义的解释是:检索结果和用户查询的相关程度。而从广义的层面,相关性可以理解为为用户查询的综合满意度。直观的来看,从用户进入搜索框的那一刻起,到需求获得满足为止,这之间经历的过程越顺畅,越便捷,搜索相关性就越好。本文总结业界常用的相关性评价指标和量化评价方法。供对此感兴趣的朋友参考。Cranfield评价体系A Cranfield 阅读全文

posted @ 2013-03-19 13:21 Harveyaot 阅读(421) 评论(0) 推荐(0) 编辑

Web scraper open source
摘要:ByadminOnSeptember 10, 2012·Add CommentWhat we know about open soucre web scrapping software?There are many open source scrapers out there. They’re free, but they do require a good deal of time to setup.At the very basic level, you can use wget which can easily be installed in almost any machin 阅读全文

posted @ 2013-03-15 14:30 Harveyaot 阅读(889) 评论(0) 推荐(0) 编辑

沉默&积累
摘要:准备好心情,开始第一份正式的工作了。我想在这里见证自己一步步在skiil上的成长!告诉自己一句话,Do whatever you like!成长~ 阅读全文

posted @ 2013-03-15 09:56 Harveyaot 阅读(148) 评论(0) 推荐(0) 编辑

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

统计

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