hi all! i think there should be no functional difference in the two code snippets below, but is there any difference in performance? (i know, the "except AttributeError" could possibly mask an AttributeError in the called function...) 1.: hook = getattr(o, '_before_transaction_commit', None) if hook: hook() 2.: try: o._before_transaction_commit() except AttributeError: pass regards, juergen herrmann _______________________________________________________________________
XLhost.de - eXperts in Linux hosting <<
Juergen Herrmann Weiherweg 10, 93051 Regensburg, Germany Fon: +49 (0)700 XLHOSTDE [0700 95467833] Fax: +49 (0)721 151 463027 ICQ: 27139974 - IRC: #XLhost@quakenet WEB: http://www.XLhost.de
--On 1. Juli 2005 17:10:58 +0200 Jürgen Herrmann <Juergen.Herrmann@XLhost.de> wrote:
hi all!
i think there should be no functional difference in the two code snippets below, but is there any difference in performance?
You could benchmark it :-) -aj
On 7/1/05, Jürgen Herrmann <Juergen.Herrmann@xlhost.de> wrote:
i think there should be no functional difference in the two code snippets below, but is there any difference in performance?
Don't know, and don't care; these are (at the Python level) functionally different.
(i know, the "except AttributeError" could possibly mask an AttributeError in the called function...)
Exactly. Shouldn't be a real issue in a released version, but better safe than sorry.
1.: hook = getattr(o, '_before_transaction_commit', None) if hook: hook()
Better yet: hook = getattr(o, '_before_transaction_commit', None) if hook is not None: hook() -Fred -- Fred L. Drake, Jr. <fdrake at gmail.com> Zope Corporation
participants (3)
-
Andreas Jung -
Fred Drake -
Jürgen Herrmann