装饰师什么时候? [英] decorators when?

查看:58
本文介绍了装饰师什么时候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么版本添加了装饰器(使用

@decorator语法)?


(有没有一般的方法我可以自己找到答案? )


有没有这样的东西,从__future__导入一些东西

会使装饰工作在2.5.2?

David C. Ullrich

What version added decorators (using the
@decorator syntax)?

(Is there a general way I could have found out the answer myself?)

Is there a somthing such that "from __future__ import something"
will make decorators work in 2.5.2?
David C. Ullrich

推荐答案

David C. Ullrich写道:
David C. Ullrich wrote:

什么版本添加装饰器(使用

@decorator语法)?


(有没有一般的方法我可以自己找到答案?)


有没有这样的东西,从__future__导入一些东西

会使装饰工作在2.5.2?
What version added decorators (using the
@decorator syntax)?

(Is there a general way I could have found out the answer myself?)

Is there a somthing such that "from __future__ import something"
will make decorators work in 2.5.2?



他们确实有效。它们是在python2.4中介绍的。

Diez

They do work. They were introduced in python2.4

Diez


On Tue,2008年5月27日14:50:23 +0200," ; Diez B. Roggisch

< de *** @ nospam.web.dewrote:
On Tue, 27 May 2008 14:50:23 +0200, "Diez B. Roggisch"
<de***@nospam.web.dewrote:

> David C. Ullrich写道:
>David C. Ullrich wrote:

>添加了什么版本的装饰器(使用
@decorator语法)?

(有一般方式我本来可以找到答案吗?)

是否有一些东西,来自__future__导入的东西
会使装饰工作在2.5.2?
>What version added decorators (using the
@decorator syntax)?

(Is there a general way I could have found out the answer myself?)

Is there a somthing such that "from __future__ import something"
will make decorators work in 2.5.2?


他们确实有效。它们是在python2.4中引入的。


They do work. They were introduced in python2.4



这或多或少是我想的,但是...


哦。别介意细节,让我们说在同一台机器上安装2.3和

2.5会导致混淆

关于你正在运行的那个一个脚本。

Duh。


对不起。谢谢。我不认为装饰器是可用的
来自__future__的
2.3?

That''s more or less what I thought, but...

Oh. Never mind the details, let''s just say that having 2.3 and
2.5 installed on the same machine can lead to confusion
about exactly which one you''re running a script under.
Duh.

Sorry. Thanks. I don''t suppose that decorators are available
from __future__ somehow in 2.3?


> Diez
>Diez



David C. Ullrich

David C. Ullrich


En Tue,2008年5月27日11:52:25 -0300,David C. Ullrich

< du ****** @sprynet.comescribió:
En Tue, 27 May 2008 11:52:25 -0300, David C. Ullrich
<du******@sprynet.comescribió:

哦。别介意细节,让我们说在同一台机器上安装2.3和

2.5会导致混淆

关于你正在运行的那个一个脚本。

Duh。
Oh. Never mind the details, let''s just say that having 2.3 and
2.5 installed on the same machine can lead to confusion
about exactly which one you''re running a script under.
Duh.



您可以更改提示;把这些行放在你的sitecustomize.py(或

创建它,如果你没有):


import sys

sys.ps1 =''p23''

sys.ps2 =''...''

You might change the prompt; put these lines in your sitecustomize.py (or
create it if you don''t have one):

import sys
sys.ps1 = ''p23''
sys.ps2 = '' ... ''


对不起。谢谢。我不认为装饰者可以在2.3中以某种方式从__future__获得

Sorry. Thanks. I don''t suppose that decorators are available
from __future__ somehow in 2.3?



不是。但装饰者只是语法糖。


@decorator

def f ():

...


与以下内容相同:


def f():< br $>
...

f = decorator(f)


(更方便)


-

Gabriel Genellina

No. But a decorator is only syntax sugar.

@decorator
def f():
...

is the same thing as:

def f():
...
f = decorator(f)

(just more convenient)

--
Gabriel Genellina


这篇关于装饰师什么时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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