{"id":181,"date":"2015-01-13T16:14:49","date_gmt":"2015-01-13T16:14:49","guid":{"rendered":"http:\/\/drsfenner.org\/blog\/?p=181"},"modified":"2015-01-13T16:14:49","modified_gmt":"2015-01-13T16:14:49","slug":"going-all-meta-part-2-some-python-fu","status":"publish","type":"post","link":"https:\/\/drsfenner.org\/blog\/2015\/01\/going-all-meta-part-2-some-python-fu\/","title":{"rendered":"Going All Meta (Part 2)  &#8211; Some Python-Fu"},"content":{"rendered":"<p>In a previous <a title=\"Going All Meta (Part 1)\" href=\"http:\/\/drsfenner.org\/blog\/?p=155\">post<\/a> (a long, long time ago), I said I was going to talk about metaclasses (or at least show an abuse of them) in Python. I am going to get to that, but I want to set the stage by talking about another topic that isn&#8217;t nearly as\u00a0<i>black-magic-y<\/i>: decorators. When I&#8217;m teaching or training, people commonly ask about decorators because they have seen them and they are confused by them &#8211; mainly because a common type of decorator is a function that takes in, modifies, and returns a different function. Huh. Back to meta-ville.<\/p>\n<p>Simply put, a decorator is a Python function with some special characteristics. That Python function takes a single, lonely input. The decorator can either be a function-decorator or a class-decorator. In the first case, the decorator take a function as its input and produces a (modified) function as its output. In the second case, it takes a class as its input and produces a (modified) class as its output.<\/p>\n<p>The raw notebook: <a href=\"http:\/\/drsfenner.org\/public\/notebooks\/DecoratorFun-00-FunctionTiming.ipynb\">Decorator Fun &#8211; Function Timing (raw)<\/a><\/p>\n<p>As seen by nbviewer: <a href=\"http:\/\/nbviewer.ipython.org\/url\/drsfenner.org\/public\/notebooks\/DecoratorFun-00-FunctionTiming.ipynb\">Decorator Fun &#8211; Function Timing (through nbviewer)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a previous post (a long, long time ago), I said I was going to talk about metaclasses (or at least show an abuse of them) in Python. I am going to get to that, but I want to set the stage by talking about another topic that isn&#8217;t nearly as\u00a0black-magic-y: decorators. When I&#8217;m teaching [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,13],"tags":[],"class_list":["post-181","post","type-post","status-publish","format-standard","hentry","category-mrdr","category-python"],"_links":{"self":[{"href":"https:\/\/drsfenner.org\/blog\/wp-json\/wp\/v2\/posts\/181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/drsfenner.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/drsfenner.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/drsfenner.org\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/drsfenner.org\/blog\/wp-json\/wp\/v2\/comments?post=181"}],"version-history":[{"count":9,"href":"https:\/\/drsfenner.org\/blog\/wp-json\/wp\/v2\/posts\/181\/revisions"}],"predecessor-version":[{"id":205,"href":"https:\/\/drsfenner.org\/blog\/wp-json\/wp\/v2\/posts\/181\/revisions\/205"}],"wp:attachment":[{"href":"https:\/\/drsfenner.org\/blog\/wp-json\/wp\/v2\/media?parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/drsfenner.org\/blog\/wp-json\/wp\/v2\/categories?post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/drsfenner.org\/blog\/wp-json\/wp\/v2\/tags?post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}