Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'none:': 0.07; '__init__': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'attribute,': 0.16; 'message- id:@post.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'repeatedly.': 0.16; 'written,': 0.19; 'header:User-Agent:1': 0.23; 'decorators': 0.24; 'instance,': 0.24; 'header:X-Complaints-To:1': 0.27; 'raise': 0.29; 'specified': 0.30; 'received:132': 0.31; 'writes:': 0.31; 'another': 0.32; 'checking': 0.33; 'subject:from': 0.34; 'too': 0.37; 'easily': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'central': 0.64; 'andrea': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Wolfgang Maier Subject: Re: decorator to fetch arguments from global objects Date: Wed, 19 Jun 2013 08:03:17 +0000 (UTC) References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: sea.gmane.org User-Agent: Loom/3.14 (http://gmane.org/) X-Loom-IP: 132.230.1.31 (Mozilla/5.0 (Windows NT 6.1; rv:21.0) Gecko/20100101 Firefox/21.0) 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371629017 news.xs4all.nl 15925 [2001:888:2000:d::a6]:45345 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48696 Wolfgang Maier biologie.uni-freiburg.de> writes: > > andrea crotti gmail.com> writes: > > > 2013/6/18 Terry Reedy udel.edu> > > > > Decorators are only worthwhile if used repeatedly. What you specified can > easily be written, for instance, as > > def save_doc(db=None): > >   if db is None: > >     db = fetch_from_global() > >   if isinstance(db, dbclass): > >     save_it() > >   else: > >     raise ValueError('need dbobject')  Another suggestion, without knowing too much about your code's architecture: why not *initialize* your Entity instance with a db_out attribute, so you do Terry's db checking only in one central place - Entity's __init__ method? Wolfgang