Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #48729 > unrolled thread
| Started by | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| First post | 2013-06-19 12:44 -0400 |
| Last post | 2013-06-19 12:44 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: decorator to fetch arguments from global objects Terry Reedy <tjreedy@udel.edu> - 2013-06-19 12:44 -0400
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2013-06-19 12:44 -0400 |
| Subject | Re: decorator to fetch arguments from global objects |
| Message-ID | <mailman.3588.1371660313.3114.python-list@python.org> |
On 6/19/2013 4:03 AM, Wolfgang Maier wrote:
> 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?
Your pair of posts pretty much say what I was trying to get at. If
Entity does not prepresent anything, it should not exist, and the
'methods' should be functions with boilerplate factored out. If entity
does represent anything, it should be the parameter common to all
methods, the db. I had not really cognized before that an advantage of
defining a class is to setup and validate the central object just once.
It is still not clear to me why db should ever by bound to None. That
must have something to do with the undisclosed context.
--
Terry Jan Reedy
Back to top | Article view | comp.lang.python
csiph-web