-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc.py
83 lines (50 loc) · 1.12 KB
/
misc.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#coding: utf-8
__author__ = 'sean.li'
#exec and compile comand
code = "for i in range(10): print i"
cmpcode = compile(code,'','exec')
exec cmpcode
code = "print 1"
cmpcode = compile(code,'','single')
exec cmpcode
# id command 显示内存地址,深拷贝浅拷贝
a=1
b=a
id(a)
id(b)
#reload
import os
reload(os)
#三元运算
a=raw_input('input')
b=raw_input('input')
a = 'equal' if a==b else 'unequal'
print a
#lambda
a= lambda x,y:x+y
print a(4,10)
#yield 迭代 生成器
#enumerate
a= [1,2,3,4]
for x,y in enumerate(a):
print x,y
# format
a= 'my name is {0} i am {1} years old'
print a.format('sean',20)
#apply 方式执行函数
def func(arg):
return arg
print apply(func,('aaaaa'))
#getatter 反射
modeule = __import__('os')
#print all attributes and functions
dir(modeule)
func = getattr(modeule,"popen")
func()
#利用getattr制作自定义路由
#
# url('^(?p<view>(\w+))/(?p<action>(\w+)))$',Execute)
#上面把url里的值当作字典({view:'testview',action:'add'})传给Execute方法去解析出指定的view和action
#exec 把字符串当成表达式执行
exec "import os"
#compile