<?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/"
		>
<channel>
	<title>Comments on: Default arguments in Python: two easy blunders</title>
	<atom:link href="http://www.deadlybloodyserious.com/2008/05/default-argument-blunders/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.deadlybloodyserious.com/2008/05/default-argument-blunders/</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 03 Sep 2009 18:10:55 +1000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Python pitfall: Passing Mutable Objects as Default Args &#171; Parerga und Paralipomena</title>
		<link>http://www.deadlybloodyserious.com/2008/05/default-argument-blunders/comment-page-1/#comment-16726</link>
		<dc:creator>Python pitfall: Passing Mutable Objects as Default Args &#171; Parerga und Paralipomena</dc:creator>
		<pubDate>Mon, 18 May 2009 15:18:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.deadlybloodyserious.com/?p=2055#comment-16726</guid>
		<description>[...] in default arguments are calculated when the function is defined, not when it’s called (read this as well). The solution is to pass None as the default value, and then add a line &#8216;listaexit = [...]</description>
		<content:encoded><![CDATA[<p>[...] in default arguments are calculated when the function is defined, not when it’s called (read this as well). The solution is to pass None as the default value, and then add a line &#8216;listaexit = [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SEO</title>
		<link>http://www.deadlybloodyserious.com/2008/05/default-argument-blunders/comment-page-1/#comment-8548</link>
		<dc:creator>SEO</dc:creator>
		<pubDate>Wed, 17 Sep 2008 21:59:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.deadlybloodyserious.com/?p=2055#comment-8548</guid>
		<description>I had similar problems to the second one using delayed javascript functions.  Thanks for the heads up.</description>
		<content:encoded><![CDATA[<p>I had similar problems to the second one using delayed javascript functions.  Thanks for the heads up.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Omer</title>
		<link>http://www.deadlybloodyserious.com/2008/05/default-argument-blunders/comment-page-1/#comment-8465</link>
		<dc:creator>Omer</dc:creator>
		<pubDate>Sun, 14 Sep 2008 02:07:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.deadlybloodyserious.com/?p=2055#comment-8465</guid>
		<description>Omg. Thanks so much! I&#039;ve been struggling with this same problem for like an hour!</description>
		<content:encoded><![CDATA[<p>Omg. Thanks so much! I&#8217;ve been struggling with this same problem for like an hour!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Denis</title>
		<link>http://www.deadlybloodyserious.com/2008/05/default-argument-blunders/comment-page-1/#comment-5800</link>
		<dc:creator>Denis</dc:creator>
		<pubDate>Tue, 01 Jul 2008 18:38:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.deadlybloodyserious.com/?p=2055#comment-5800</guid>
		<description>I just hit Blunder#2. I&#039;m pretty sure it isn&#039;t the first time, but I felt compelled to get to the root of it once and for all. In the end, I feel disappointed with this violation of the &quot;you get what you expect&quot; principle that generally pervades the realm of Pythonese.

If I had wanted a class instance variable, I would have declared one, I&#039;m not shy about it, honest. Is this truly not considered a bug in the interpreter?</description>
		<content:encoded><![CDATA[<p>I just hit Blunder#2. I&#8217;m pretty sure it isn&#8217;t the first time, but I felt compelled to get to the root of it once and for all. In the end, I feel disappointed with this violation of the &#8220;you get what you expect&#8221; principle that generally pervades the realm of Pythonese.</p>
<p>If I had wanted a class instance variable, I would have declared one, I&#8217;m not shy about it, honest. Is this truly not considered a bug in the interpreter?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: garth</title>
		<link>http://www.deadlybloodyserious.com/2008/05/default-argument-blunders/comment-page-1/#comment-5600</link>
		<dc:creator>garth</dc:creator>
		<pubDate>Thu, 12 Jun 2008 05:51:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.deadlybloodyserious.com/?p=2055#comment-5600</guid>
		<description>I put the open() with the rest of the code that does the work; I find it easier to read. Great use of an &quot;and&quot; in that last line, too.</description>
		<content:encoded><![CDATA[<p>I put the open() with the rest of the code that does the work; I find it easier to read. Great use of an &#8220;and&#8221; in that last line, too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: swr</title>
		<link>http://www.deadlybloodyserious.com/2008/05/default-argument-blunders/comment-page-1/#comment-5526</link>
		<dc:creator>swr</dc:creator>
		<pubDate>Sun, 01 Jun 2008 20:50:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.deadlybloodyserious.com/?p=2055#comment-5526</guid>
		<description>Jay said,
ON MAY 9TH, 2008 AT 12:57 PM

file = None

try:
file = open(’/tmp/somefile’)
finally:
file and file.close()

why putting &#039;open&#039; into the try-finally block?
If it fails there is nothing to close anyway.
I was repeating such construction many times until I realized it&#039;s a bit illogical.</description>
		<content:encoded><![CDATA[<p>Jay said,<br />
ON MAY 9TH, 2008 AT 12:57 PM</p>
<p>file = None</p>
<p>try:<br />
file = open(’/tmp/somefile’)<br />
finally:<br />
file and file.close()</p>
<p>why putting &#8216;open&#8217; into the try-finally block?<br />
If it fails there is nothing to close anyway.<br />
I was repeating such construction many times until I realized it&#8217;s a bit illogical.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: garth</title>
		<link>http://www.deadlybloodyserious.com/2008/05/default-argument-blunders/comment-page-1/#comment-5419</link>
		<dc:creator>garth</dc:creator>
		<pubDate>Thu, 15 May 2008 01:24:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.deadlybloodyserious.com/?p=2055#comment-5419</guid>
		<description>I just batch-approved all these excellent comments. Thanks in particular for all the reminders to use the &#039;or&#039; operator. Cheers!</description>
		<content:encoded><![CDATA[<p>I just batch-approved all these excellent comments. Thanks in particular for all the reminders to use the &#8216;or&#8217; operator. Cheers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jasko</title>
		<link>http://www.deadlybloodyserious.com/2008/05/default-argument-blunders/comment-page-1/#comment-5408</link>
		<dc:creator>Jasko</dc:creator>
		<pubDate>Mon, 12 May 2008 17:26:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.deadlybloodyserious.com/?p=2055#comment-5408</guid>
		<description>How about something like this to handle both cases?

def report(when=time.time):
... 	if hasattr(when, &quot;__call__&quot;):
... 		print when()
... 	else:
... 		print when

&gt;&gt;&gt; report()
1210613185.87
&gt;&gt;&gt; report(&quot;Now&quot;)
Now

Though regarding your second example --- yowza! I can see a sleepless night worrying about that one!</description>
		<content:encoded><![CDATA[<p>How about something like this to handle both cases?</p>
<p>def report(when=time.time):<br />
&#8230; 	if hasattr(when, &#8220;__call__&#8221;):<br />
&#8230; 		print when()<br />
&#8230; 	else:<br />
&#8230; 		print when</p>
<p>&gt;&gt;&gt; report()<br />
1210613185.87<br />
&gt;&gt;&gt; report(&#8221;Now&#8221;)<br />
Now</p>
<p>Though regarding your second example &#8212; yowza! I can see a sleepless night worrying about that one!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: me</title>
		<link>http://www.deadlybloodyserious.com/2008/05/default-argument-blunders/comment-page-1/#comment-5399</link>
		<dc:creator>me</dc:creator>
		<pubDate>Sun, 11 May 2008 10:58:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.deadlybloodyserious.com/?p=2055#comment-5399</guid>
		<description>the report example would be simpler with

def report(when=None):
    when = when or time.time()
    print when</description>
		<content:encoded><![CDATA[<p>the report example would be simpler with</p>
<p>def report(when=None):<br />
    when = when or time.time()<br />
    print when</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://www.deadlybloodyserious.com/2008/05/default-argument-blunders/comment-page-1/#comment-5391</link>
		<dc:creator>David</dc:creator>
		<pubDate>Sat, 10 May 2008 13:06:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.deadlybloodyserious.com/?p=2055#comment-5391</guid>
		<description>For the report function, I would use this implementation :
&gt;&gt;&gt; def report(when=time.time):
…     print when()

Note that no parenthesis are used in the default parameter.</description>
		<content:encoded><![CDATA[<p>For the report function, I would use this implementation :<br />
&gt;&gt;&gt; def report(when=time.time):<br />
…     print when()</p>
<p>Note that no parenthesis are used in the default parameter.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
