tag:blogger.com,1999:blog-8427412129779288317.post6250793389906350957..comments2024-01-31T02:41:38.165-05:00Comments on Concision and Concinnity: Decorator Factories (and decorator factory factories)Ian McCrackenhttp://www.blogger.com/profile/11153934961249932934noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-8427412129779288317.post-88444101150940535102013-05-15T11:14:00.596-04:002013-05-15T11:14:00.596-04:00You certainly can do that. It totally depends on t...You certainly can do that. It totally depends on the situation. There are cases where you might want to create enough reusable decorators that a factory makes more sense.<br /><br />For example, say you're writing the (useless) library "pyexponent", which provides decorators for raising things to various powers. You might certainly provide your example, @raiser(2), but you might Ian McCrackenhttps://www.blogger.com/profile/11153934961249932934noreply@blogger.comtag:blogger.com,1999:blog-8427412129779288317.post-69769203165143075162013-05-12T03:20:23.648-04:002013-05-12T03:20:23.648-04:00So... why can't you just put multiple paramete...So... why can't you just put multiple parameters in your decorator factory, instead of adding another level?<br /><br />For that matter... why can't you just add a second parameter to your decorator, rather than creating a "factory"? Some thing like:<br /><br />def decorator(exponent, f):<br />[...]<br /><br />And then you can do "timestwo = decorator(2, timestwo)", orAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8427412129779288317.post-71558133604730135492011-01-19T17:24:11.699-05:002011-01-19T17:24:11.699-05:00Indeed. A fantastic explanation!Indeed. A fantastic explanation!Kevin Hhttps://www.blogger.com/profile/03013155163736662271noreply@blogger.comtag:blogger.com,1999:blog-8427412129779288317.post-14608261537818471602010-09-09T19:39:51.938-04:002010-09-09T19:39:51.938-04:00Great article!
It helped me to finally understand ...Great article!<br />It helped me to finally understand the difference between decorators with and without parameters in python.Anonymousnoreply@blogger.com