<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Python decorator mini-study (part 2 of 3)</title>
	<atom:link href="http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/</link>
	<description>Cool ideas revolving around computers and programming</description>
	<lastBuildDate>Tue, 15 Dec 2009 18:31:07 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: arjuna</title>
		<link>http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/#comment-5154</link>
		<dc:creator>arjuna</dc:creator>
		<pubDate>Thu, 17 Jul 2008 07:17:40 +0000</pubDate>
		<guid isPermaLink="false">http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/#comment-5154</guid>
		<description>Me too Thanks... I have been wondering what all this unpythonic function nesting was all about...this article made it clearer, thanks</description>
		<content:encoded><![CDATA[<p>Me too Thanks&#8230; I have been wondering what all this unpythonic function nesting was all about&#8230;this article made it clearer, thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hasen</title>
		<link>http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/#comment-5153</link>
		<dc:creator>hasen</dc:creator>
		<pubDate>Tue, 08 Jul 2008 04:00:41 +0000</pubDate>
		<guid isPermaLink="false">http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/#comment-5153</guid>
		<description>thanks a ton man, great article, helped me a lot!!</description>
		<content:encoded><![CDATA[<p>thanks a ton man, great article, helped me a lot!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Z</title>
		<link>http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/#comment-5144</link>
		<dc:creator>James Z</dc:creator>
		<pubDate>Mon, 23 Jun 2008 07:27:10 +0000</pubDate>
		<guid isPermaLink="false">http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/#comment-5144</guid>
		<description>Thanks dude, great article on python decorators. There seems to be no mention of python decorators in Dive Into Python book, nor the python tutorial on python.org.</description>
		<content:encoded><![CDATA[<p>Thanks dude, great article on python decorators. There seems to be no mention of python decorators in Dive Into Python book, nor the python tutorial on python.org.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Miscellanea and a Pycon closeout &#8212; jessenoller.com</title>
		<link>http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/#comment-5064</link>
		<dc:creator>Miscellanea and a Pycon closeout &#8212; jessenoller.com</dc:creator>
		<pubDate>Fri, 28 Mar 2008 01:12:34 +0000</pubDate>
		<guid isPermaLink="false">http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/#comment-5064</guid>
		<description>[...] Non-Typing news, this post (and this one) on Python Decorators is quite good, although more recently I saw some code that looked like [...]</description>
		<content:encoded><![CDATA[<p>[...] Non-Typing news, this post (and this one) on Python Decorators is quite good, although more recently I saw some code that looked like [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: see whatever&#8230; &#187; Deprecation decorator</title>
		<link>http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/#comment-3311</link>
		<dc:creator>see whatever&#8230; &#187; Deprecation decorator</dc:creator>
		<pubDate>Sun, 14 Oct 2007 10:55:23 +0000</pubDate>
		<guid isPermaLink="false">http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/#comment-3311</guid>
		<description>[...] an individual message which contains information about how to avoid the deprecated method. I found this parameterized decorator example and customized it for my [...]</description>
		<content:encoded><![CDATA[<p>[...] an individual message which contains information about how to avoid the deprecated method. I found this parameterized decorator example and customized it for my [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: muharem</title>
		<link>http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/#comment-6</link>
		<dc:creator>muharem</dc:creator>
		<pubDate>Fri, 20 Oct 2006 13:45:13 +0000</pubDate>
		<guid isPermaLink="false">http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/#comment-6</guid>
		<description>Hello Brian,

thank you for pointing this out! I&#039;ll amend  part2 to include your correction.
&lt;blockquote&gt;

#!/usr/bin/env python
&quot;&quot;&quot;variant simple decorator example&quot;&quot;&quot;

from sys import stdout

&lt;b&gt;def&lt;/b&gt; interceptor(before, after):
    &lt;b&gt;def&lt;/b&gt; interceptor_inner(f):
        &lt;b&gt;def&lt;/b&gt; wrapper(*args, **kwargs):
            stdout.write(before)
            f(*args, **kwargs)
            stdout.write(after)
        &lt;b&gt;return&lt;/b&gt; wrapper
    &lt;b&gt;return&lt;/b&gt; interceptor_inner

@interceptor(&#039;&gt;&gt; &#039;, &#039; &lt;&lt;\n&#039;)
&lt;b&gt;def&lt;/b&gt; plf(): stdout.write(&quot;Help! I am only a poor little function!\n&quot;)

&lt;b&gt;if&lt;/b&gt; __name__ == &#039;__main__&#039;:
    plf()

e&gt;

&lt;/code&gt;
&lt;/blockquote&gt;</description>
		<content:encoded><![CDATA[<p>Hello Brian,</p>
<p>thank you for pointing this out! I&#8217;ll amend  part2 to include your correction.</p>
<blockquote>
<p>#!/usr/bin/env python<br />
&quot;&quot;&quot;variant simple decorator example&quot;&quot;&quot;</p>
<p>from sys import stdout</p>
<p><b>def</b> interceptor(before, after):<br />
    <b>def</b> interceptor_inner(f):<br />
        <b>def</b> wrapper(*args, **kwargs):<br />
            stdout.write(before)<br />
            f(*args, **kwargs)<br />
            stdout.write(after)<br />
        <b>return</b> wrapper<br />
    <b>return</b> interceptor_inner</p>
<p>@interceptor(&#8216;&gt;&gt; &#8216;, &#8216; &lt;&lt;\n&#8217;)<br />
<b>def</b> plf(): stdout.write(&quot;Help! I am only a poor little function!\n&quot;)</p>
<p><b>if</b> __name__ == &#8216;__main__&#8217;:<br />
    plf()</p>
<p>e&gt;</p>
</blockquote>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/#comment-5</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Fri, 20 Oct 2006 12:48:55 +0000</pubDate>
		<guid isPermaLink="false">http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/#comment-5</guid>
		<description>My indentation got mangled there.  The corresponding decorator is:

print &quot;&quot;&quot;
def interceptor(before, after):
&#124;   def decorator(f):
&#124;   &#124;   def wrapper(*args, **kwargs):
&#124;   &#124;   &#124;   stdout.write(before)
&#124;   &#124;   &#124;   f(*args, **kwargs)
&#124;   &#124;   &#124;   stdout.write(after)
&#124;   &#124;   return wrapper
&#124;   return decorator
&quot;&quot;&quot;.replace(&quot;&#124;   &quot;,&quot;    &quot;)</description>
		<content:encoded><![CDATA[<p>My indentation got mangled there.  The corresponding decorator is:</p>
<p>print &#8220;&#8221;"<br />
def interceptor(before, after):<br />
|   def decorator(f):<br />
|   |   def wrapper(*args, **kwargs):<br />
|   |   |   stdout.write(before)<br />
|   |   |   f(*args, **kwargs)<br />
|   |   |   stdout.write(after)<br />
|   |   return wrapper<br />
|   return decorator<br />
&#8220;&#8221;".replace(&#8220;|   &#8220;,&#8221;    &#8220;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/#comment-4</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Fri, 20 Oct 2006 12:39:14 +0000</pubDate>
		<guid isPermaLink="false">http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/#comment-4</guid>
		<description>&gt;Complex decorators have to be implemented as classes.

This is not true - you can implement your interceptor decorator using just functions as below:

def interceptor(before, after):
    def decorator(f):
        def wrapper(*args, **kwargs):
            stdout.write(before)
            f(*args, **kwargs)
            stdout.write(after)
        return wrapper
    return decorator

What is actually happening is that _calling_ the interceptor function is returning the decorator to use, which is then called as per the normal decorator application.  The same thing as is happening with the class version, where calling creates and returns an instance, which is then used as the decorator, and called.</description>
		<content:encoded><![CDATA[<p>&gt;Complex decorators have to be implemented as classes.</p>
<p>This is not true &#8211; you can implement your interceptor decorator using just functions as below:</p>
<p>def interceptor(before, after):<br />
    def decorator(f):<br />
        def wrapper(*args, **kwargs):<br />
            stdout.write(before)<br />
            f(*args, **kwargs)<br />
            stdout.write(after)<br />
        return wrapper<br />
    return decorator</p>
<p>What is actually happening is that _calling_ the interceptor function is returning the decorator to use, which is then called as per the normal decorator application.  The same thing as is happening with the class version, where calling creates and returns an instance, which is then used as the decorator, and called.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
