装饰者 - 不仅仅是语法糖 [英] decorators - more than just syntactic sugar

查看:123
本文介绍了装饰者 - 不仅仅是语法糖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




装饰器不仅仅是python 2.x中的语法糖和什么

关于python 3k?

如何找到预定义的装饰器?


非常感谢您的帮助,


Helmut Jarausch


Lehrstuhl fuer Numerische Mathematik

RWTH - 亚琛大学

D 52056德国亚琛

解决方案

2007年8月11日星期六20:30:54 + 0200,Helmut Jarausch写道:


不仅仅是python 2.x中的语法糖装饰器什么

关于python 3k?



它们只是语法糖。


@spam

def ham():

通过





def ham()相同:

通过


ham =垃圾邮件(火腿)


如何查找预定义的装饰器?



* *预定义装饰器?毕竟装饰器只是功能。

有一些意味着用作装饰器,但也有

"普通的"作为装饰者可能有意义的功能。


Ciao,

Marc''BlackJack''Rintsch


< blockquote> 8月11日晚上8:30,Helmut Jarausch< jarau ... @ skynet.bewrote:





装饰器不仅仅是python 2.x中的语法糖和什么

关于python 3k?



好​​吧,我认为语法糖很重要(所有Turing

完整语言只有语法糖不同)并且有或没有



a给定语法糖在写作之间有所不同

写作

a给定程序。在核心Python中使用装饰器会让我们以不同的方式思考



看看David Mertz的文章

http://www.ibm.com/developerworks/li...l-cpdecor.html


Michele Simionato


8月11日晚上8:30,Helmut Jarausch< jarau ... @ skynet.bewrote:


如何找到预定义的装饰器?



我敢说'这并不容易。由于装饰器只是(?)

语法糖,他们没有通过独特的声明元素获得表达的特定语义

。与识别生成器表达式的生成器不同,装饰器可以在语法识别时使用.b
。但是根据你的意图,这可能足够了吗?


Hi,

are decorators more than just syntactic sugar in python 2.x and what
about python 3k ?
How can I find out the predefined decorators?

Many thanks for your help,

Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany

解决方案

On Sat, 11 Aug 2007 20:30:54 +0200, Helmut Jarausch wrote:

are decorators more than just syntactic sugar in python 2.x and what
about python 3k ?

They are just syntactic sugar.

@spam
def ham():
pass

is the same as

def ham():
pass

ham = spam(ham)

How can I find out the predefined decorators?

*The* predefined decorators? Decorators are just functions after all.
There are some meant to be used as decorators but there are also
"ordinary" functions that may make sense as decorators.

Ciao,
Marc ''BlackJack'' Rintsch


On Aug 11, 8:30 pm, Helmut Jarausch <jarau...@skynet.bewrote:

Hi,

are decorators more than just syntactic sugar in python 2.x and what
about python 3k ?

Well, I argued may times that syntactic sugar is important (all Turing
complete languages differs by syntactic sugar only) and having or not
having
a given syntactic sugar makes a difference between writing and not
writing
a given program. Having decorators in core Python makes us think
differently.
Have a look at David Mertz article

http://www.ibm.com/developerworks/li...l-cpdecor.html

Michele Simionato


On Aug 11, 8:30 pm, Helmut Jarausch <jarau...@skynet.bewrote:

How can I find out the predefined decorators?

I dare to say that''s not easy. Since decorators are just(?)
syntactical sugar they don''t obtain a particular semantics expressed
by distinctive declarative elements. Unlike generators which can be
identified looking for a yield expression a decorator can be
identified syntactically just when it is used. However this might be
sufficient, depending on your intention?


这篇关于装饰者 - 不仅仅是语法糖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆