摘要: 在mac 上安装过程有些区折http://stackoverflow.com/questions/20325473/error-installing-python-image-library-using-pip-on-mac-os-x-10-9?lq=1ln -s /usr/local/includ... 阅读全文
posted @ 2014-11-14 19:37 zhangxiaodel 阅读(284) 评论(0) 推荐(0) 编辑
摘要: 1 2 --------------------对象用Counter------------------------------------------------------------- 3 4 dc={"james":4,"kim":3,"marry":5,"bill":6} 5 ... 阅读全文
posted @ 2014-06-12 16:25 zhangxiaodel 阅读(3164) 评论(0) 推荐(0) 编辑
摘要: 1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 4 import re 5 import urllib 6 7 def getHtml(url): 8 page=urllib.urlopen(url) 9 html=pag... 阅读全文
posted @ 2014-04-26 10:57 zhangxiaodel 阅读(301) 评论(0) 推荐(0) 编辑
摘要: 1 # -*- coding: utf-8 -*- 2 __author__ = 'admin' 3 4 5 #主要是目录相关的操作 6 7 import os 8 9 import shutil10 11 12 #os.mkdir('download')13 #os.rmdir('download')14 15 #os.makedirs('a/b/c',)16 17 #os.removedirs('a/b/c')18 os.chdir('.')19 20 #print os.getcwd()21 阅读全文
posted @ 2014-02-25 22:51 zhangxiaodel 阅读(215) 评论(0) 推荐(0) 编辑
摘要: 欢迎进入Flask大型教程项目!http://www.pythondoc.com/flask-mega-tutorial/index.html所使用的 python 扩展flask\Scripts\pip install flask==0.9flask\Scripts\pip install flask-loginflask\Scripts\pip install flask-openidflask\Scripts\pip install flup 阅读全文
posted @ 2014-02-19 10:53 zhangxiaodel 阅读(677) 评论(0) 推荐(0) 编辑
摘要: 摘自http://www.cnblogs.com/Alexander-Lee/archive/2010/07/01/1769097.htmlWHY PYTHON Rocks人们学习PHP是因为要得到一份工作;人们学习Java是因为他们选修了计算机科学这门课;人们学习Python是因为他们爱这门语言,因为他们追寻美,如果我雇佣了一个Python程序员,他很有可能是优秀的程序员。以上的话是Rails On Ruby的创始人在一次与人讨论的时候如是说转战Python已经4个月了,想总结一下为什么会选择python,为什么程序员应该学习Python,使用Python可以为你带来什么。首先,python 阅读全文
posted @ 2014-02-19 10:35 zhangxiaodel 阅读(301) 评论(0) 推荐(0) 编辑
摘要: import osfor (p,d,f) in os.walk("要删除的目录路径"): if p.find('.svn')>0: os.popen('rd /s /q %s'%p)转自 http://www.cnblogs.com/Alexander-Lee/archive/2010/02/23/1671905.html 阅读全文
posted @ 2014-02-19 09:53 zhangxiaodel 阅读(245) 评论(0) 推荐(0) 编辑
摘要: http://liuzhijun.iteye.com/blog/1859857 阅读全文
posted @ 2014-01-21 22:03 zhangxiaodel 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 1 2 3 4 5 Document 6 7 8 9 10 {%for item in nav %}11 {{item}} 12 {%endfor%}13 14 15 16 17 18 hello world {{uname}}19 20 文档列表21 {{blog}}22 23 {%for k,v in blog.items()%}24 25 {{k}}:{{v}}26 {%endfor%}27 28 29 30 1 __author__ = 'a... 阅读全文
posted @ 2013-12-31 17:05 zhangxiaodel 阅读(612) 评论(0) 推荐(0) 编辑
摘要: 1 ''' 2 json study 3 4 ''' 5 import json 6 d={} 7 d['id']=123 8 d['name']='jerry' 9 d['tags']=('english','movie','pingpang')10 d['fav']=['movie','music','pingpang']11 12 13 print(d)14 15 w 阅读全文
posted @ 2013-12-31 16:59 zhangxiaodel 阅读(330) 评论(0) 推荐(0) 编辑
摘要: 转自csdn lambda表达式返回一个函数对象例子:func = lambda x,y:x+yfunc相当于下面这个函数def func(x,y): return x+y注意def是语句而lambda是表达式下面这种情况下就只能用lambda而不能用def[(lambda x:x*x)(x) for x in range(1,11)]map,reduce,filter中的function都可以用lambda表达式来生成!map(function,sequence)把sequence中的值当参数逐个传给function,返回一个包含函数执行结果的list。如果function有两个参数,即m. 阅读全文
posted @ 2013-12-31 16:56 zhangxiaodel 阅读(315) 评论(0) 推荐(0) 编辑
摘要: 1 select counters ,input_user ,hours,minutes,counters/minutes as perMinute,counters/hours as perHour from 2 ( 3 SELECT count(*) counters,`录入员` input_user, 4 timestampdiff(hour, '2013-04-21 14:21:43', '2013-04-21 14:35:12') as 5 hours, 6 timestampdiff(minute, '2013-04-21 14:21:4.. 阅读全文
posted @ 2013-12-11 14:35 zhangxiaodel 阅读(1462) 评论(0) 推荐(0) 编辑
摘要: 综合例子 random,[] 1 # -*- coding: UTF-8 -*- 2 import random; 3 4 5 list=["石头","剪刀","布","ok"] 6 7 guize=[["石头","剪刀"],["剪刀","布"],["布","石头"]] 8 9 while True:10 skey=random.choice(list); #random.randint(1, 1 阅读全文
posted @ 2013-12-11 14:28 zhangxiaodel 阅读(322) 评论(0) 推荐(0) 编辑
摘要: 1 f=open("sql.txt") 2 fout=open("out.txt","w") 3 line=f.readline() 4 while line: 5 print line 6 fout.write(line) 7 line=f.readline() 8 9 f.close()10 fout.close() 1 try: 2 f=open("raw_input.py") 3 lines= f.readlines() 4 print lines 5 f.seek(0) 6 fout=open(" 阅读全文
posted @ 2013-12-11 14:26 zhangxiaodel 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 1 for number in range(1,5): 2 print number 3 4 print range(4) 5 # [0, 1, 2, 3] 6 7 8 xx=[x*x for x in range(4)] 9 print xx10 #[0, 1, 4, 9]11 12 xx=[x*x for x in range(4) if x % 3==0]13 print xx14 #[0, 9]15 16 xx=[(x,y) for x in range(3) for y in range(3)]17 print xx18 #[(0, 0), (0, 1), (0, 2... 阅读全文
posted @ 2013-12-11 14:20 zhangxiaodel 阅读(233) 评论(0) 推荐(0) 编辑
摘要: 1 #coding utf-8 2 3 __author__ = 'thinkpad' 4 5 numbers=[1,2,3,4,5,6,7,8,9,10] 6 print(numbers) 7 print len(numbers) 8 #[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 9 10 print numbers[1:10:2]11 #[2, 4, 6, 8, 10]12 13 14 print numbers[2:6]15 #[3, 4, 5, 6]16 17 print numbers[10:2:-2]18 #[10, 8, 6, 4]19 20 阅读全文
posted @ 2013-12-11 14:13 zhangxiaodel 阅读(192) 评论(0) 推荐(0) 编辑
摘要: raw_input1 print "hello world"2 3 name=raw_input("what is your name? ")4 print "hello ["+name +"] !"5 6 raw_input("press to close")raw_input 过滤空值 1 name='' 2 while not name or name.isspace(): 3 name=raw_input('type in your name: ') 4 阅读全文
posted @ 2013-12-11 14:05 zhangxiaodel 阅读(315) 评论(0) 推荐(0) 编辑
摘要: 1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 4 import ordereddict 5 6 list1=['jim','marry','terrence'] 7 list2=[13,15,18] 8 12 def unionListToDict(list1, list2):13 result = ordereddict.OrderedDict()14 for i in range(len(list1)):15 #print list1[i],list2[i]16 result[l... 阅读全文
posted @ 2013-12-11 12:27 zhangxiaodel 阅读(350) 评论(0) 推荐(0) 编辑
摘要: 简单方法声明及调用 1 def hello(name='world', id=0):2 return "hello %s %s" % (name, id)3 4 5 str = hello('kimi', 3)可变参数 1 def nums(a,b,c,*arg,**args): 2 print(a,b,c) 3 print(arg) 4 print(args) 5 6 nums(1,2,3,4,(1,2,3)) 7 8 #输出为 9 (1, 2, 3)10 (4, (1, 2, 3))11 {}字典参数1 #字典需要声明及使用时 2个参数 阅读全文
posted @ 2013-12-11 12:24 zhangxiaodel 阅读(200) 评论(0) 推荐(0) 编辑
摘要: __author__ = 'admin'# -*- coding: utf-8 -*-class Ren(): name="human" def say(self): print('can speak')class Chinese(Ren): name = 'chinese people'#多重继承 使用先继承者的属性 ,可调整顺序实现想要的属性 ,且只#继承第一个的 __init__ 方法class Beijing(Chinese,Ren): passRen.name='a human'print(Ren.n 阅读全文
posted @ 2013-12-11 11:55 zhangxiaodel 阅读(151) 评论(0) 推荐(0) 编辑
摘要: python2.7 在32,64位win7 上字符集是不同的 。在安装easy_install时候会体现出来,会报 mimetypes 错误 ,只需将出错的哪一段代码注释掉。这个问题也困扰了我很久,直到一位老友在国外的某个网站上查到了关于此问题的资料。如下: 1 try: 2 ctype = _winreg.EnumKey(mimedb, i) 3 except EnvironmentError: 4 break 5 # ... 阅读全文
posted @ 2013-12-11 11:47 zhangxiaodel 阅读(175) 评论(0) 推荐(0) 编辑