avatar
python decorator 调用问题# Programming - 葵花宝典
N*9
1
现急需San Diego食品Demo人员一名。主要工作是在超市将食品让客人试吃。
要求女性,面貌端正,口齿伶俐,年龄在20-40之间,会中文(广东话或普通话均可)
和少许英文。
工作时间固定在每个星期的周末。
欢迎有身份的学生和家庭主妇加入。有意者请于近日将电话号码发送到[email protected]
yahoo.com。必有回复。谢谢!
avatar
c*e
2
我觉得太阳能的窗户,transparent solar panel
应该是个很大的发展空间,那么多 大楼什么的 ,
有什么新产品,新发展么,挺想 做这个,可是不是学
这个的皮爱着第
avatar
i*0
3
这个礼拜四,奥巴马要开始讨论移民改革了
07/01/2010
avatar
c*o
4
rt
haha
avatar
T*o
5
RE
avatar
j*k
6
比如有下面一个decorator, 怎么调用?
def decorator(func,aa):
def wrapper(*args, **argd):
if aa:
func(*args, **argd)
return wrapper
@decorator
def myfunc(a1,a2)
or
@decorator(True)
def myfunc(a1,a2)
都不行。
谢谢
avatar
s*i
7
应该是选择性涂层,接受/反射不同波长的太阳光。
avatar
m*g
8
就是在American University发表演讲吧。到时看看有什么新意没有
avatar
k*r
9
把aa定义在decorator外面试试看,比如

aa = False
def mydecorator(func):
def wrapper(*args, **argd):
if aa:
func(*args, **argd)
return wrapper


【在 j*****k 的大作中提到】
: 比如有下面一个decorator, 怎么调用?
: def decorator(func,aa):
: def wrapper(*args, **argd):
: if aa:
: func(*args, **argd)
: return wrapper
: @decorator
: def myfunc(a1,a2)
: or
: @decorator(True)

avatar
c*e
10
是的 ,把可见光弄进来,红外的吸收之类
有产品 么。。

【在 s*i 的大作中提到】
: 应该是选择性涂层,接受/反射不同波长的太阳光。
avatar
b*g
11
我看到他周三的演讲,提到外国学生学engineering和computer science结果无法留下
来的问题,他说我们培养了竞争
avatar
j*k
12
别人的decorator是定义好的,没法改
我这儿只是举个例子,想搞清楚怎么调用法

【在 k***r 的大作中提到】
: 把aa定义在decorator外面试试看,比如
:
: aa = False
: def mydecorator(func):
: def wrapper(*args, **argd):
: if aa:
: func(*args, **argd)
: return wrapper
:

avatar
J*1
13
avatar
T*k
14
That's right. But rednecks don't care.

【在 b******g 的大作中提到】
: 我看到他周三的演讲,提到外国学生学engineering和computer science结果无法留下
: 来的问题,他说我们培养了竞争

avatar
i*f
15
This decorator definition seems not make sense to me.
From your dec. definition, it's obvious it takes two arguments: func, aa. So:
@decorator
def f():
...
is transformed to:
decorator(func, aa)(f)
Your decorator is **got** to take exactly two arguments. If this is the case
, seems that the wrapper is not doing what you want.
Are you trying to do something like:
def decorator(aa):
def outer_wrapper(func):
def wrapper(*args, **argd):
if

【在 j*****k 的大作中提到】
: 比如有下面一个decorator, 怎么调用?
: def decorator(func,aa):
: def wrapper(*args, **argd):
: if aa:
: func(*args, **argd)
: return wrapper
: @decorator
: def myfunc(a1,a2)
: or
: @decorator(True)

avatar
s*i
16
不少 -- 一般的玻璃窗就有这个功能;要强化的化应该也不贵。
avatar
j*k
17
yeah, the decorator has two parameters in which the first one is the
function.
just want to know how to use it.
Thanks

So:
case

【在 i*****f 的大作中提到】
: This decorator definition seems not make sense to me.
: From your dec. definition, it's obvious it takes two arguments: func, aa. So:
: @decorator
: def f():
: ...
: is transformed to:
: decorator(func, aa)(f)
: Your decorator is **got** to take exactly two arguments. If this is the case
: , seems that the wrapper is not doing what you want.
: Are you trying to do something like:

avatar
c*e
18
我咋看了觉得不是那么容易的被“不少”来形容呢。
这种panel其实就是dye solar panel, 产品狠新的说阿。
国内似乎也没有公司作者个,请问你是学者方面的么?

【在 s*i 的大作中提到】
: 不少 -- 一般的玻璃窗就有这个功能;要强化的化应该也不贵。
avatar
d*e
19
如果要用@decorator调用,我觉得不能这么写decorator。这种写法你只能
直接
>>>new_func = decorator(func,aa)
这个tutorial写的挺清楚的,
http://www.artima.com/weblogs/viewpost.jsp?thread=240845
看最下面的Decorator Functions with Decorator Arguments.

【在 j*****k 的大作中提到】
: 比如有下面一个decorator, 怎么调用?
: def decorator(func,aa):
: def wrapper(*args, **argd):
: if aa:
: func(*args, **argd)
: return wrapper
: @decorator
: def myfunc(a1,a2)
: or
: @decorator(True)

avatar
d*1
20
目前肯定不行的。再国50年看看
avatar
r*t
21
这个不是 decorator, 只是一个名字叫 decorator 的function,语法上看是一个
closure,
decorator is invoked with the function object as the only argument.

【在 j*****k 的大作中提到】
: yeah, the decorator has two parameters in which the first one is the
: function.
: just want to know how to use it.
: Thanks
:
: So:
: case

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。