Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53788
| From | Gildor Oronar <gildororonar@mail-on.us> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: to be pythonic: should caller or callee log? |
| Date | 2013-09-06 23:05 +0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <5229EF57.3090709@mail-on.us> (permalink) |
| References | <l051gb$li5$1@dont-email.me> <mailman.17.1378242095.5461.python-list@python.org> <l06ocs$vo2$2@dont-email.me> <148ea321-c4e3-457b-bcc8-865f480c80b6@googlegroups.com> |
El 04/09/13 20:14, Xaxa Urtiz escribió:
> and what about something like that :
>
>
> class AbsctractAccount():
> def transaction(self, amount, target):
> logging.info("Start transaction of %s to %s" % (amount, target))
> self.DoTransaction(amount,target)
>
> def DoTransaction(self,amount,target):
> pass # or raise notimplemented or do not implement this methods in the abstract class
> ...
>
> class DebitAccount(AbstractAccount):
> def DoTransaction(self, amount, target):
> ...
>
> class SomeOtherAccount(...)
> ....
> like that you only have to write the logging function once.
Thanks for the hint! This also work well, and has the advantage of being
specific to this function -- I did use decorator as Ethan suggested,
which works for most of the case, but there is function (other than
transaction) needs specialized logging because the function doesn't
return anything but changes a class variable -- using a special
decorator for just one function is over-generalizing, and your method
kicks in.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
to be pythonic: should caller or callee log? Gildor Oronar <gildororonar@mail-on.us> - 2013-09-04 00:07 +0800
Re: to be pythonic: should caller or callee log? Terry Reedy <tjreedy@udel.edu> - 2013-09-03 17:01 -0400
Re: to be pythonic: should caller or callee log? Gildor Oronar <gildororonar@mail-on.us> - 2013-09-04 15:44 +0800
Re: to be pythonic: should caller or callee log? Xaxa Urtiz <urtizvereaxaxa@gmail.com> - 2013-09-04 05:14 -0700
Re: to be pythonic: should caller or callee log? Gildor Oronar <gildororonar@mail-on.us> - 2013-09-06 23:05 +0800
Re: to be pythonic: should caller or callee log? Ethan Furman <ethan@stoneleaf.us> - 2013-09-03 19:26 -0700
Re: to be pythonic: should caller or callee log? Gildor Oronar <gildororonar@mail-on.us> - 2013-09-04 15:44 +0800
csiph-web