12 2013 档案

摘要:import sysimport BaseHTTPServerfrom SimpleHTTPServer import SimpleHTTPRequestHandlerHandlerClass = SimpleHTTPRequestHandlerServerClass = BaseHTTPServer.HTTPServerProtocol = "HTTP/1.0"if sys.argv[1:]: port = int(sys.argv[1])else: port = 8000server_address = ('127.0.0.1',port)Handler 阅读全文
posted @ 2013-12-29 21:49 画家与我 阅读(695) 评论(0) 推荐(0)
摘要:import smtplibSMTPserver = 'smtp.163.com'fromaddr = 'a@163.com'toaddr = 'b@qq.com'MsgHead = ['From:a@163.com','To:b@qq.com','Subject':'Lalalal']MsgBody = ['balalla','aaaaa']Msg = '\r\n\r\n'.join(['\r\n'.join(MsgH 阅读全文
posted @ 2013-12-29 20:57 画家与我 阅读(328) 评论(0) 推荐(0)
摘要:http://kenby.iteye.com/blog/1162698importlogging#创建一个loggerlogger=logging.getLogger('mylogger')logger.setLevel(logging.DEBUG)#创建一个handler,用于写入日志文件fh=logging.FileHandler('test.log')fh.setLevel(logging.DEBUG)#再创建一个handler,用于输出到控制台ch=logging.StreamHandler()ch.setLevel(logging.DEBUG)#定义h 阅读全文
posted @ 2013-12-27 14:52 画家与我 阅读(162) 评论(0) 推荐(0)
摘要:eggs.cvs文件为:http://www.crifan.com/python_read_write_csv_file/ 阅读全文
posted @ 2013-12-27 14:43 画家与我 阅读(198) 评论(0) 推荐(0)
摘要:hashlib是个专门提供hash算法的库,现在里面包括md5, sha1, sha224, sha256, sha384, sha512,使用非常简单、方便。 md5经常用来做用户密码的存储。而sha1则经常用作数字签名。 阅读全文
posted @ 2013-12-27 14:24 画家与我 阅读(226) 评论(0) 推荐(0)
摘要:difflib是python提供的比较序列(string list)差异的模块。实现了三个类:1>SequenceMatcher 任意类型序列的比较 (可以比较字符串)2>Differ 对字符串进行比较3>HtmlDiff 将比较结果输出为html格式.SequenceMatcher实例:SequeceMatcher(None,a,b)创建序列比较对象,将以a作为参考标准进行Sequecematcher(None,b,a)创建序列比较对象,将以b作为参考标准进行a,b表示待比较的两个序列,生成序列比较对象后,调用该对象的get_opcodes()方法,将返回一个元组(tag, 阅读全文
posted @ 2013-12-27 14:14 画家与我 阅读(3758) 评论(0) 推荐(0)
摘要:http://open.weibo.com/apps,创建新的应用,进入创建的应用后,在接口管理中就能找到29组常用的开放接口了。首先从最简单的用户普通读取接口开始,/users/show,需要传递的参数有用户uid,以及Oauth的Access_token,虽然这个Access_token是key和secret生成的,但是我每次都还是要在API测试工具中获取,然后用自己写的简单requests类得到相应的结果。 阅读全文
posted @ 2013-12-26 23:26 画家与我 阅读(212) 评论(0) 推荐(0)
摘要:1.list--列表(1)append:(2)count:>>> x = ['to','bee','or','not','to']>>> x.count('to')2>>> x.count('apple')0(3)extend:列表尾部一次性追加另一个序列>>> a=[1,2,3]>>> b=[4,5,6]>>> a.extend(b)>>> a[1, 2, 阅读全文
posted @ 2013-12-25 14:31 画家与我 阅读(324) 评论(0) 推荐(0)
摘要:1.finger -p 用户名 用户名:存放在/etc/passwd中 阅读全文
posted @ 2013-12-22 16:19 画家与我 阅读(128) 评论(0) 推荐(0)
摘要:今天偶然写两个灰常简单的类,Point,Rectangle,即左上角和右下角标识一个矩形的类。#include class Point{public: Point(); Point(int x); Point(int x,int y); int getX(); int getY(); void setX(int new_val); void setY(int new_val); void printPoint();private: int x; int y;};Point::Point(int x):x(x),y(x){};Point::Point():x(0),y(0){... 阅读全文
posted @ 2013-12-18 20:04 画家与我 阅读(1781) 评论(0) 推荐(0)
摘要:telnet 127.0.0.1 11211之后,可以用的命令有:(1)stats(2)stats itemsReturns some information, broken down by slab, about items stored in memcached.(3)stats slabsReturns more information, broken down by slab, about items stored in memcached. More centered to performance of a slab rather than counts of particular 阅读全文
posted @ 2013-12-18 12:44 画家与我 阅读(347) 评论(0) 推荐(0)
摘要:因为要垮表查询,数据量大,为了访问方便,决定在django项目中加入缓存,第一次接触,所以就先用memcached尝试了一下,效果不错,但是由于每次缓存的触发都是在查该条记录时放进memcache的,所以第一次的访问还是狠慢,所以考虑在后台跑一个单独的进程,逐条缓存各记录,由于暂时celery(大芹菜)没大看懂,暂时采用命令行方式执行,能够达到目的。。。。。但是对于数据所占用的内存大小,每次存的单位大小,以及失效时间,都暂时没有详细考虑,尤其是失效时间的选择上,不好决定,不合适的设定将很大程度上降低memcache命中率。再者就是项目系统为实时性的,怎么做才能使数据尽早得到更新呢??? ... 阅读全文
posted @ 2013-12-12 23:56 画家与我 阅读(233) 评论(0) 推荐(0)
摘要:1.use [database]; desc [table_name]; select * from [table_name]; 阅读全文
posted @ 2013-12-10 13:55 画家与我 阅读(135) 评论(0) 推荐(0)
摘要:1.phpmyadmin的安装 sudo apt-get install phpmyadmin 之后发现http://localhost/phpmyadmin显示没有此url,于是想到本机上能显示的网页都在/var/www文件夹内,因此执行命令行:sudo ln /usr/share/phpmyadmin /var/www 这样就能使用了; 之后遇到的问题是登陆,phpmyadmin的登陆用户名和密码与mysql相同,但我的mysql密码为空,因此要到 /var/www/phpmyadmin/libraries/config.default.php 中修改一个配置选项,$cfg['Se 阅读全文
posted @ 2013-12-10 13:39 画家与我 阅读(884) 评论(0) 推荐(0)
摘要:一. 安装 比较纠结,按照网上的装法总是Connection Refused ,但是看redis却是启动的状态,没有任何其他的错误信息,于是装了卸卸了装,折腾好半天,最后决定先在Mac里装吧,结果过程与其相同,原来是版本问题呀,晕~然后原样在Ubuntu也装撑了。 cd /tmp wget http://redis.googlecode.com/files/redis-2.6.9.tar.gz tar zxf redis-2.6.9.tar.gz cd redis-2.6.9 make sudo make install make test:看时候通过然后下载一些配置文件(主要就是把d... 阅读全文
posted @ 2013-12-06 13:45 画家与我 阅读(124) 评论(0) 推荐(0)
摘要:url(r'^static/(?P.*)$',django.views.static.serve,{'document_root':settings.STATIC_ROOT}),} 阅读全文
posted @ 2013-12-06 13:39 画家与我 阅读(185) 评论(0) 推荐(0)
摘要:Brett.IsBlogging about all kinds of thingsMy Python Web Crawlerwritten by brett langdonHow to write a very simplistic Web Crawler in Python forfun.Recently I decided to take on a new project, a Python basedweb crawlerthat I am dubbing Breakdown. Why? I have always been interested in web crawlers and 阅读全文
posted @ 2013-12-04 12:53 画家与我 阅读(394) 评论(0) 推荐(0)
摘要:1.sudo apt-get install apache2 sudo apt-get install php5 sudo apt-get install libapache2-mod-php5sudo apt-get install libapache2-mod-auth-mysql sudo /etc/init.d/apache2 restartsudo apt-get install libapache2-mod-python apt-get remove --purge apache2.2-common, 阅读全文
posted @ 2013-12-03 17:10 画家与我 阅读(117) 评论(0) 推荐(0)
摘要:urllib.unquote()字符串被当作url提交时会被自动进行url编码处理,在python里也有个urllib.urlencode的方法,可以很方便的把字典形式的参数进行url编码。可是在分析httpheaders的传输信息时,很多已经被url编码的字符串,不是我们这些菜鸟一眼能看出来的,于是乎,urllib.unquote()s ="url=%2F&email=imtesting%40tempmail.com&password=hereispassword"print urllib.unquote(s)>>> url=/& 阅读全文
posted @ 2013-12-03 16:05 画家与我 阅读(444) 评论(0) 推荐(0)
摘要:python中对文件、文件夹(文件操作函数)的操作需要涉及到os模块和shutil模块。得到当前工作目录,即当前Python脚本工作的目录路径:os.getcwd()返回指定目录下的所有文件和目录名:os.listdir()函数用来删除一个文件:os.remove()删除多个目录:os.removedirs(r“c:\python”)检验给出的路径是否是一个文件:os.path.isfile()检验给出的路径是否是一个目录:os.path.isdir()判断是否是绝对路径:os.path.isabs()检验给出的路径是否真地存:os.path.exists()返回一个路径的目录名和文件名:os 阅读全文
posted @ 2013-12-03 12:55 画家与我 阅读(195) 评论(0) 推荐(0)
摘要:首先建立项目,XXX按照github上的命令行提示:(1)终端上将项目克隆到本地,git clone https://github.com/username/projectname.git (2)touch README.md (3)git init: 【Initialized empty Git repository in /home/song/code/.git/】(4)git add README.md (5)git commit -m "first commit" (6)cd 项目 git remote add originhttps://github.com/us 阅读全文
posted @ 2013-12-02 19:23 画家与我 阅读(205) 评论(0) 推荐(0)
摘要:from reportlab.pdfgen import canvasdef some_view(request): response = HttpResponse(mimetype='application/pdf') response['Content-Disposition'] ='attachement;filename=somefilename.pdf' p = canvas.Canvas(response) p.drawString(100,100,"Hello World.") p.showPage() p.sa 阅读全文
posted @ 2013-12-01 22:47 画家与我 阅读(180) 评论(0) 推荐(0)