decorator to fetch arguments from global objects
Wolfgang Maier
wolfgang.maier at biologie.uni-freiburg.de
Wed Jun 19 04:03:17 EDT 2013
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
More information about the Python-list
mailing list