本文介绍了装饰师什么时候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 什么版本添加了装饰器(使用 @decorator语法)? (有没有一般的方法我可以自己找到答案? ) 有没有这样的东西,从__future__导入一些东西 会使装饰工作在2.5.2? David C. UllrichWhat 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推荐答案 他们确实有效。它们是在python2.4中介绍的。 DiezThey do work. They were introduced in python2.4Diez 他们确实有效。它们是在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 and2.5 installed on the same machine can lead to confusionabout exactly which one you''re running a script under.Duh.Sorry. Thanks. I don''t suppose that decorators are availablefrom __future__ somehow in 2.3? David C. UllrichDavid C. Ullrich 您可以更改提示;把这些行放在你的sitecustomize.py(或 创建它,如果你没有): import sys sys.ps1 =''p23'' sys.ps2 =''...''You might change the prompt; put these lines in your sitecustomize.py (orcreate it if you don''t have one):import syssys.ps1 = ''p23''sys.ps2 = '' ... '' 不是。但装饰者只是语法糖。 @decorator def f (): ... 与以下内容相同: def f(): ... f = decorator(f) (更方便) - Gabriel GenellinaNo. But a decorator is only syntax sugar.@decoratordef f():...is the same thing as:def f():...f = decorator(f)(just more convenient)--Gabriel Genellina 这篇关于装饰师什么时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-14 08:07