🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.objects
Article #16431

Re: AOP

#16431
From: Wojciech Muła
Date: Thu, 12 Apr 2007 22:50
31 lines
1987 bytes
A.L. wrote:
>>Wazne jest jeszcze to ze dekorator moze
>>sobie jako atrybuty dekorowanej funkcji/metody
>>funkcji zapamietac cokolwiek.
>  
> Co to znaczy "zapamietac"?... Gdzie zapamietac? I co sie stanie z
> owymi zapamietanymi rzeczami jak funkcja zrobi "return"?...

Dekorator może zwrócić nową funkcję, w której kontekście (closure)
będzie zapamiętany dodatkowy argument/argumenty.  Poniżej przykład.

def dekorator(argument):
     def helper(fun):
         def wrapper(*args):
             print "argument dekoratora =", argument
             return fun(*args)
         return wrapper
     return helper

@dekorator("argument")
def foo1():
     pass

@dekorator([10, 1.0, "xxx"])
def foo2():
     pass

foo1()
foo2()

w.
Technical Details
Message-ID: <evmd5f$3d$1@atlantis.news.tpi.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!newsfeed.tpinternet.pl!atlantis.news.tpi.pl!news.tpi.pl!not-for-mail
References: <evl4uq$mem$1@inews.gazeta.pl> <evla3n$ip1$1@tkdami.pl> <vh4t13l8k9cjuvjncu5l1isfa1vkn4335e@4ax.com> <evm55h$7ds$1@tkdami.pl> <qd6t13l10bkpa55tme7msq5no2ng9icigs@4ax.com> <evm7pd$t7q$1@inews.gazeta.pl> <evm8so$5is$1@inews.gazeta.pl> <vt9t131g9ofrk8ca4vimhn31j6ob7a0tl5@4ax.com> <evmbl7$hse$1@inews.gazeta.pl> <e1dt131qk76481jc9vrf2dahup47ev65d6@4ax.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!newsfeed.tpinternet.pl!atlantis.news.tpi.pl!news.tpi.pl!not-for-mail
From: Wojciech Muła
 <wojciech_mula@poczta.null.onet.pl.invalid>
Newsgroups: pl.comp.objects
Subject: Re: AOP
Date: Fri, 13 Apr 2007 00:50:43 +0200
Organization: tp.internet - http://www.tpi.pl/
Lines: 31
Message-ID: <evmd5f$3d$1@atlantis.news.tpi.pl>
References: <evl4uq$mem$1@inews.gazeta.pl> <evla3n$ip1$1@tkdami.pl> <vh4t13l8k9cjuvjncu5l1isfa1vkn4335e@4ax.com> <evm55h$7ds$1@tkdami.pl> <qd6t13l10bkpa55tme7msq5no2ng9icigs@4ax.com> <evm7pd$t7q$1@inews.gazeta.pl> <evm8so$5is$1@inews.gazeta.pl> <vt9t131g9ofrk8ca4vimhn31j6ob7a0tl5@4ax.com> <evmbl7$hse$1@inews.gazeta.pl> <e1dt131qk76481jc9vrf2dahup47ev65d6@4ax.com>
NNTP-Posting-Host: acbp94.neoplus.adsl.tpnet.pl
Mime-Version: 1.0
X-Trace: atlantis.news.tpi.pl 1176418288 109 83.9.113.94 (12 Apr 2007 22:51:28 GMT)
X-Complaints-To: usenet@tpi.pl
NNTP-Posting-Date: Thu, 12 Apr 2007 22:51:28 +0000 (UTC)
User-Agent: Icedove 1.5.0.10 (X11/20070329)
In-Reply-To: <e1dt131qk76481jc9vrf2dahup47ev65d6@4ax.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit