Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'finally:': 0.07; 'exit': 0.09; 'modulo': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'try:': 0.09; 'subject:How': 0.10; 'def': 0.12; 'b):': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'integer': 0.24; 'header:X-Complaints-To:1': 0.27; '"",': 0.31; 'division': 0.31; 'file': 0.32; '(most': 0.33; 'to:addr:python-list': 0.38; 'recent': 0.39; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'subject:have': 0.80; 'divide': 0.84; 'subject: . ': 0.84; 'subject:want': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: I want to print entry and exit message for functions , i have bunch of such function . How can i do it in decorator. Date: Fri, 20 Sep 2013 15:23:13 +0200 Organization: None References: <30bf5567-47ff-4b54-acc4-aebb0451e47d@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084b822.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1379683376 news.xs4all.nl 16000 [2001:888:2000:d::a6]:49622 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54472 bab mis wrote: > def fun: > print "entry" > . > . > print "exit" >>> def log(f): ... def g(*args, **kw): ... print "enter", f.__name__ ... try: ... return f(*args, **kw) ... finally: ... print "exit", f.__name__ ... return g ... >>> @log ... def divide(a, b): ... return a / b ... >>> divide(4, 2) enter divide exit divide 2 >>> divide(4, 0) enter divide exit divide Traceback (most recent call last): File "", line 1, in File "", line 5, in g File "", line 3, in divide ZeroDivisionError: integer division or modulo by zero