This topic created in 4686 days ago, the information mentioned may be changed or developed.
比如
def cache(store,datasource):
这个datasorce可能是一个url,也可能是从读数据库, 在调用的时候传一个函数读取数据源, 业务代码统一用 cache(store,datsource)这样的方式调用,不用区别是数据库,还是网络
14 replies • 1970-01-01 08:00:00 +08:00
 |
|
3
xingxiucun Aug 8, 2013
@ yakczh 1 def a(): 2 print 'a' 3 4 def b(): 5 print 'b' 6 7 8 9 def e(m): 10 m() 11 12 13 14 e(a) 不清楚你是不是这个意思
|
 |
|
4
TK Aug 8, 2013
>>> def eval(fun, a): ... print(fun(a)) ... >>> eval(sum, [1, 2]) 3
|
 |
|
5
binux Aug 8, 2013
如果类型不同的时候需要在cache里自行判断参数类型,以做不同动作
|
 |
|
8
qdvictory Aug 8, 2013
@ yakczh m(a,'hello word') def m(func,str): funcA(str) def funcA(str): print str
|
 |
|
9
qdvictory Aug 8, 2013
@ yakczh m(a,'hello word') def m(func,str): func(str) def a(str): print str 上一条搞混乱了- -
|
 |
|
10
likuku Aug 8, 2013
@ yakczh >>> def a (k): ... print k ... >>> a('s') s >>> def b(e): ... e ... >>> b(a('lll')) lll
|
 |
|
12
TK Aug 9, 2013 via Android
|
 |
|
13
yakczh Aug 9, 2013
如果 要传入的函数带参数,其中一部分参数是主流程的数据,一部分参数是调用时动态传入的,这种情况怎么下
比如
def linkhandle(urls,prefix):
urls=list(map( lambda x: x.replace('./',prefix), urls )) print(urls) return urls
def workflow(handle): urls=['./201207/t20120705_1887040.html', './201206/t20120608_1846662.html'] link=handle(urls) urls=workflow(linkhandle("http://")) urls=workflow(linkhandle('https://'))
print(urls)
将主流程中的url链接通过传入handle+参数 来重新格式化
|
 |
|
14
bh3887 Aug 9, 2013
可以参阅decorator
|