Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #48696

Re: decorator to fetch arguments from global objects

From Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
Subject Re: decorator to fetch arguments from global objects
Date 2013-06-19 08:03 +0000
References <CAF_E5JYg39VdwmLFnyXNOMPRx1UD8ZNGiBRpqgU=A_9rU_ukpw@mail.gmail.com> <kppv2q$shk$1@ger.gmane.org> <CAF_E5JZ3afve8WxOS_vmL_i9vC863uVYc723fV4NPAS=xod7vQ@mail.gmail.com> <loom.20130619T090208-281@post.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.3574.1371629017.3114.python-list@python.org> (permalink)

Show all headers | View raw


Wolfgang Maier <wolfgang.maier <at> biologie.uni-freiburg.de> writes:

> 
> andrea crotti <andrea.crotti.0 <at> gmail.com> writes:
>  
> > 2013/6/18 Terry Reedy <tjreedy <at> 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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: decorator to fetch arguments from global objects Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2013-06-19 08:03 +0000

csiph-web