12 2013 档案
摘要: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...
阅读全文
摘要: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
阅读全文
摘要:转自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.
阅读全文
摘要: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..
阅读全文
摘要:综合例子 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
阅读全文
摘要: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("
阅读全文
摘要: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...
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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...
阅读全文
摘要:简单方法声明及调用 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个参数
阅读全文
摘要:__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
阅读全文
摘要:python2.7 在32,64位win7 上字符集是不同的 。在安装easy_install时候会体现出来,会报 mimetypes 错误 ,只需将出错的哪一段代码注释掉。这个问题也困扰了我很久,直到一位老友在国外的某个网站上查到了关于此问题的资料。如下: 1 try: 2 ctype = _winreg.EnumKey(mimedb, i) 3 except EnvironmentError: 4 break 5 # ...
阅读全文

浙公网安备 33010602011771号