随笔分类 -  Python

摘要:main.py#!/bin/python #coding=utf-8 import tornado.ioloop import tornado.web,pymongo,datetime class BaseHandler(tornado.web.RequestHandler): def today(self): date=datetime.datetime.now() year=str(date.year)[-2:] month=str(date.month) da... 阅读全文
posted @ 2013-11-10 20:57 Epirus 阅读(254) 评论(0) 推荐(0)
摘要:#!/bin/python#encoding=utf-8import urllib,lxml.html,lxml.html.soupparser,re,pymongourl1="http://sou.zhaopin.com/jobs/SearchResult.ashx?in=210500%3b160400%3b160000&pd=1&jl=%E7%A6%8F%E5%B7%9E&sm=0&et=2&p=1"url="http://sou.zhaopin.com/jobs/SearchResult.ashx?in=210500% 阅读全文
posted @ 2013-11-10 12:32 Epirus 阅读(507) 评论(0) 推荐(0)
摘要:这个世界的核心制度一定要定制得清晰,不然就是一片混乱,不管怎么样都是浮云~别靠说的,那点实际的 阅读全文
posted @ 2013-11-10 11:15 Epirus 阅读(132) 评论(0) 推荐(0)
摘要:#!/bin/python#coding=utf-8import urllib,xlrd,lxml.html,re,pymongo,xlwtfail=open('fail','w')def getDocument(url,code='utf-8'): try: doc=lxml.html.fromstring(urllib.urlopen(url).read().decode(code)) print 'utf-8' except: doc=lxml.html.fromstring(urllib.urlopen(url).read 阅读全文
posted @ 2013-11-07 17:43 Epirus 阅读(792) 评论(0) 推荐(0)
摘要:hehe 阅读全文
posted @ 2013-11-07 10:58 Epirus 阅读(580) 评论(0) 推荐(0)
摘要:#!/bin/python#coding=utf-8import re,osfilterOne='http://www.catking.com/'def getFilesNames(): return [i for i in os.listdir('./') if 'asp' in i]def replaceContent(): filesNames=getFilesNames() for name in filesNames: files=open(name) saveFile=open(name.replace('.', 阅读全文
posted @ 2013-11-02 15:38 Epirus 阅读(355) 评论(0) 推荐(0)
摘要:(r"/favicon\.ico", tornado.web.StaticFileHandler,{'path':'./'})lol 阅读全文
posted @ 2013-10-29 17:41 Epirus 阅读(550) 评论(0) 推荐(0)
摘要:#!/bin/python#coding=utf-8import osfrom PIL import Imagedir='/tmp/img/'fileName=(os.listdir(dir))size=338,266for i in fileName: suffix=i[-3:] index=fileName.index(i) im=Image.open(dir+i) im.convert('RGB').resize(size,Image.ANTIALIAS).save("/tmp/img/"+str(index)+".jpg&q 阅读全文
posted @ 2013-10-29 16:29 Epirus 阅读(3451) 评论(0) 推荐(0)
摘要://img/@srclol 阅读全文
posted @ 2013-10-29 15:18 Epirus 阅读(263) 评论(0) 推荐(0)
摘要:application = tornado.web.Application([ (r"/", MainHandler), (r'/imgs/(.*)',tornado.web.StaticFileHandler,{'path':'./imgs'}),],debug=True) 阅读全文
posted @ 2013-10-24 09:57 Epirus 阅读(427) 评论(0) 推荐(0)
摘要:这个也非常有意思,函数真的在python中地位很高呀,很多特性感觉都是特意为函数而设计的decorator就是对函数的,外围的一个修改,找不到一个合适的比喻呀,可能跟细胞核,跟细胞膜的关系吧,对进入细胞核的东西,先做一个检查,或者修饰,形成一个新的整体。最简单的例子def first(func): def wrapper(*args,**kwargs): print 'first' func() print 'finish first' return wrapper这个函数不会执行wrapper,但会返回wrapper,所以我们该怎么调用呢?def foo(): 阅读全文
posted @ 2013-09-18 14:39 Epirus 阅读(301) 评论(0) 推荐(0)
摘要:这篇文章写的真好,怎么感觉读起来就是这么的顺~有点按耐不住之感,同时还是被github page再次吸引,不知什么时候转过去。那种markdown跟git感觉真是爽爆了~https://blog.tonyseek.com/post/event-manage-with-greenlet/ 阅读全文
posted @ 2013-09-18 00:07 Epirus 阅读(1573) 评论(0) 推荐(0)
摘要:进程、线程和协程的理解进程、线程和协程之间的关系和区别也困扰我一阵子了,最近有一些心得,写一下。进程拥有自己独立的堆和栈,既不共享堆,亦不共享栈,进程由操作系统调度。线程拥有自己独立的栈和共享的堆,共享堆,不共享栈,线程亦由操作系统调度(标准线程是的)。协程和线程一样共享堆,不共享栈,协程由程序员在协程的代码里显示调度。进程和其他两个的区别还是很明显的。协程和线程的区别是:协程避免了无意义的调度,由此可以提高性能,但也因此,程序员必须自己承担调度的责任,同时,协程也失去了标准线程使用多CPU的能力。打个比方吧,假设有一个操作系统,是单核的,系统上没有其他的程序需要运行,有两个线程 A 和 B 阅读全文
posted @ 2013-09-17 21:01 Epirus 阅读(871) 评论(0) 推荐(0)
摘要:1.方式一,使用多线程import thread,timedef my(a,b): for i in range(1,20): print iif __name__=='__main__': thread.start_new_thread(my,(1,2)) thread.start_new_thread(my,(2,2))example 1这个是有错误的,应为main程序会直接退出,导致sys.excepthook is missing 的错误。这个错误产生的原因是:系统已经产生错误但是没有被捕捉到,其实很好理解import thread,timedef my... 阅读全文
posted @ 2013-09-15 19:56 Epirus 阅读(277) 评论(0) 推荐(0)
摘要:from hashlib import md5m =md5()#获取一个MD5加密算法对象m.update('string')#指定要加密的字符串m.hexdigest()#获取加密后的16进制字符串from: http://www.zhlwish.com/2010/10/11/python_file_md5/ 阅读全文
posted @ 2013-08-20 14:06 Epirus 阅读(632) 评论(0) 推荐(0)
摘要:vim 中的制表符是非常讨厌的对于python编写而言所以,我需要将tab 转成空格:set expandtab //tab 将转成空格,可是已经是tab的就没有转成空格了,所以需要下一条:%retab //将已有的tab转成空格[1]http://hi.baidu.com/jtzhbrzfdpbceid/item/c3bfd937c91932607d034b24[2]http://hi.baidu.com/ubrowlwchlbjowr/item/cb4b3e98f379a7f22816476e 阅读全文
posted @ 2013-08-08 13:42 Epirus 阅读(488) 评论(0) 推荐(0)
摘要:在读电子书的时候,双击又可以找出单词,这样子比较方便,就像金山自动取词一样,最近要看好多书,这个只能写的了草一点了,没怎么优化,代码都不好读先给图然后在copy代码还有很多的bug不过没有时间了,boss要求学习c下面附上python脚本Dictionaryimport gtk,gobject,urllibimport xml.etree.ElementTree as ETclass Dictionary: def getXML(self,word): result="" url="http://dict-co.iciba.com/api/dictionary.. 阅读全文
posted @ 2012-12-21 14:28 Epirus 阅读(199) 评论(0) 推荐(0)