<?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: Unexpected side effects in Python classes</title>
	<atom:link href="http://nvie.com/archives/470/feed" rel="self" type="application/rss+xml" />
	<link>http://nvie.com/archives/470</link>
	<description>Anything that interests me.</description>
	<lastBuildDate>Mon, 06 Sep 2010 13:45:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Aled</title>
		<link>http://nvie.com/archives/470/comment-page-1#comment-2762</link>
		<dc:creator>Aled</dc:creator>
		<pubDate>Tue, 17 Aug 2010 21:07:50 +0000</pubDate>
		<guid isPermaLink="false">http://nvie.com/?p=470#comment-2762</guid>
		<description>You probably want to read the programmer&#039;s note here: http://docs.python.org/release/2.5.1/ref/class.html</description>
		<content:encoded><![CDATA[<p>You probably want to read the programmer&#8217;s note here: <a href="http://docs.python.org/release/2.5.1/ref/class.html" rel="nofollow">http://docs.python.org/release/2.5.1/ref/class.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aled</title>
		<link>http://nvie.com/archives/470/comment-page-1#comment-3343</link>
		<dc:creator>Aled</dc:creator>
		<pubDate>Tue, 17 Aug 2010 21:07:00 +0000</pubDate>
		<guid isPermaLink="false">http://nvie.com/?p=470#comment-3343</guid>
		<description>You probably want to read the programmer&#039;s note here: http://docs.python.org/release/2.5.1/ref/class.html</description>
		<content:encoded><![CDATA[<p>You probably want to read the programmer&#8217;s note here: <a href="http://docs.python.org/release/2.5.1/ref/class.html" rel="nofollow">http://docs.python.org/release/2.5.1/ref/class.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ruslan Spivak</title>
		<link>http://nvie.com/archives/470/comment-page-1#comment-592</link>
		<dc:creator>Ruslan Spivak</dc:creator>
		<pubDate>Sun, 21 Mar 2010 02:37:33 +0000</pubDate>
		<guid isPermaLink="false">http://nvie.com/?p=470#comment-592</guid>
		<description>On a somewhat related note about mutable objects - many people new to Python are also caught off guard by the side effect of using a mutable object as a default parameter in a function/method definition:

&gt;&gt;&gt; def get_props(proplist=[]):
...          proplist.append(&#039;port=777&#039;)
...          return proplist
... 
&gt;&gt;&gt; get_props()
[&#039;port=777&#039;]

&gt;&gt;&gt; get_props()
[&#039;port=777&#039;, &#039;port=777&#039;]

&gt;&gt;&gt; get_props()
[&#039;port=777&#039;, &#039;port=777&#039;, &#039;port=777&#039;]

The problem here is that the default parameter value is evaluated once when the function definition is executed. So basically all later modifications of that parameter modify the default mutable object.

You can find more about that behavior at:
http://docs.python.org/reference/compound_stmts.html#function-definitions</description>
		<content:encoded><![CDATA[<p>On a somewhat related note about mutable objects &#8211; many people new to Python are also caught off guard by the side effect of using a mutable object as a default parameter in a function/method definition:</p>
<p>&gt;&gt;&gt; def get_props(proplist=[]):<br />
&#8230;          proplist.append(&#8216;port=777&#8242;)<br />
&#8230;          return proplist<br />
&#8230;<br />
&gt;&gt;&gt; get_props()<br />
['port=777']</p>
<p>&gt;&gt;&gt; get_props()<br />
['port=777', 'port=777']</p>
<p>&gt;&gt;&gt; get_props()<br />
['port=777', 'port=777', 'port=777']</p>
<p>The problem here is that the default parameter value is evaluated once when the function definition is executed. So basically all later modifications of that parameter modify the default mutable object.</p>
<p>You can find more about that behavior at:<br />
<a href="http://docs.python.org/reference/compound_stmts.html#function-definitions" rel="nofollow">http://docs.python.org/reference/compound_stmts.html#function-definitions</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ruslan Spivak</title>
		<link>http://nvie.com/archives/470/comment-page-1#comment-3342</link>
		<dc:creator>Ruslan Spivak</dc:creator>
		<pubDate>Sun, 21 Mar 2010 02:37:00 +0000</pubDate>
		<guid isPermaLink="false">http://nvie.com/?p=470#comment-3342</guid>
		<description>On a somewhat related note about mutable objects - many people new to Python are also caught off guard by the side effect of using a mutable object as a default parameter in a function/method definition:

&gt;&gt;&gt; def get_props(proplist=[]):
...          proplist.append(&#039;port=777&#039;)
...          return proplist
... 
&gt;&gt;&gt; get_props()
[&#039;port=777&#039;]

&gt;&gt;&gt; get_props()
[&#039;port=777&#039;, &#039;port=777&#039;]

&gt;&gt;&gt; get_props()
[&#039;port=777&#039;, &#039;port=777&#039;, &#039;port=777&#039;]

The problem here is that the default parameter value is evaluated once when the function definition is executed. So basically all later modifications of that parameter modify the default mutable object.

You can find more about that behavior at:
http://docs.python.org/reference/compound_stmts.html#function-definitions</description>
		<content:encoded><![CDATA[<p>On a somewhat related note about mutable objects &#8211; many people new to Python are also caught off guard by the side effect of using a mutable object as a default parameter in a function/method definition:</p>
<p>&gt;&gt;&gt; def get_props(proplist=[]):<br />
&#8230;          proplist.append(&#8216;port=777&#8242;)<br />
&#8230;          return proplist<br />
&#8230;<br />
&gt;&gt;&gt; get_props()<br />
['port=777']</p>
<p>&gt;&gt;&gt; get_props()<br />
['port=777', 'port=777']</p>
<p>&gt;&gt;&gt; get_props()<br />
['port=777', 'port=777', 'port=777']</p>
<p>The problem here is that the default parameter value is evaluated once when the function definition is executed. So basically all later modifications of that parameter modify the default mutable object.</p>
<p>You can find more about that behavior at:<br />
<a href="http://docs.python.org/reference/compound_stmts.html#function-definitions" rel="nofollow">http://docs.python.org/reference/compound_stmts.html#function-definitions</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
