tag:blogger.com,1999:blog-11788780.post489453517026024960..comments2023-12-29T13:22:33.104-08:00Comments on JJinuxLand: Python: A Few Decorator Tipsjjinuxhttp://www.blogger.com/profile/03270879497119114175noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-11788780.post-5925274845447993112008-07-14T19:51:00.000-07:002008-07-14T19:51:00.000-07:00> Speaking of which, check this out: http://www.he...> Speaking of which, check this out: http://www.hedgerwow.com/360/dhtml/ie6_memory_leak_fix/ (a fix to the IE6 memory leak problem using that pattern).<BR/><BR/>Very nice ;)jjinuxhttps://www.blogger.com/profile/03270879497119114175noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-46984049996490515062008-07-14T11:23:00.000-07:002008-07-14T11:23:00.000-07:00putting the return in the try, and more stuff in t...putting the return in the try, and more stuff in the finally is clever, not naughty (though, it makes mortal souls' minds hurt).<BR/><BR/>Speaking of which, check this out: <A HREF="http://www.hedgerwow.com/360/dhtml/ie6_memory_leak_fix/" REL="nofollow">http://www.hedgerwow.com/360/dhtml/ie6_memory_leak_fix/</A> (a fix to the IE6 memory leak problem using that pattern).Brandon L. Golmhttps://www.blogger.com/profile/12579635831136709134noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-56209723127559338692008-07-10T10:44:00.000-07:002008-07-10T10:44:00.000-07:00I mentioned "logged(sum)(1, 2)", but I didn't ment...I mentioned "logged(sum)(1, 2)", but I didn't mention that if you don't actually have a function like sum and you *only* want to call the decorator, you can fake it with:<BR/><BR/>logged(lambda: None)()jjinuxhttps://www.blogger.com/profile/03270879497119114175noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-27598796414234183682008-07-10T08:34:00.000-07:002008-07-10T08:34:00.000-07:00This is the decorator I use for logging, but it co...This is the decorator I use for logging, but it could be improved with the decorator module<BR/><BR/> def debug_func(self, func):<BR/> def result(*args, **kwargs):<BR/> print('---%s\ndebugging callable: %s, args: %s, kwargs: %s' % (func.__name__, func, args, kwargs))<BR/> result = None<BR/> try:<BR/> result = func(*args, **kwargs)<BR/> finally:<BR/> print('the callable %s returned: %s\n---' % (repr(func), repr(result)))<BR/> global last_debugged<BR/> last_debugged = (func, args, kwargs)<BR/> return result<BR/> result.__doc__ = func.__doc__<BR/> result.__name__ = func.__name__<BR/> return resultAnonymousnoreply@blogger.com