to be pythonic: should caller or callee log?
Gildor Oronar
gildororonar at mail-on.us
Fri Sep 6 11:05:59 EDT 2013
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.
More information about the Python-list
mailing list