<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: python class confusion</title>
	<link>http://shiftmode.com/2008/02/python-class-confusion.html</link>
	<description>zeros and ones</description>
	<pubDate>Fri, 09 Jan 2009 23:44:17 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.2</generator>
		<item>
		<title>By: shiftMode &#187; Blog Archive &#187; python class confusion II</title>
		<link>http://shiftmode.com/2008/02/python-class-confusion.html#comment-13142</link>
		<dc:creator>shiftMode &#187; Blog Archive &#187; python class confusion II</dc:creator>
		<pubDate>Fri, 22 Feb 2008 03:20:50 +0000</pubDate>
		<guid>http://shiftmode.com/2008/02/python-class-confusion.html#comment-13142</guid>
		<description>[...] am I&#8217;m glad I&#8217;m dumb. Seriously, I really need to ask more stupid questions here if these are the returns I&#8217;m going to [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] am I&#8217;m glad I&#8217;m dumb. Seriously, I really need to ask more stupid questions here if these are the returns I&#8217;m going to [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Norman Young</title>
		<link>http://shiftmode.com/2008/02/python-class-confusion.html#comment-13125</link>
		<dc:creator>Norman Young</dc:creator>
		<pubDate>Thu, 21 Feb 2008 17:23:16 +0000</pubDate>
		<guid>http://shiftmode.com/2008/02/python-class-confusion.html#comment-13125</guid>
		<description>Short answer:

t.name="remote" alters the "t" object's "name" attribute, whereas s="remote" alters only the local s variable. The astring variable remains unchanged.

Long answer:

All variables (including functions' parameters) are references to objects. Assigning a variable merely changes the object to which the variable refers.

Modules, classes and functions are objects which, when nested, define hierarchies of namespaces. The . dot notation dereferences each level within the hierarchy by implicitly querying the   object's attributes __dict__ using the key . The result of dereferencing is always an object.

At the line
   t.name=’remote’
in the example, "t" is a local variable (i.e., an implicit attribute of the "settime" method function object) referencing a passed-in object. The assignment sets that passed-in object's "name" attribute to reference the local string object "remote". (Note that this assignment occurs independently of whether or not the passed-in object had a "name" attribute previously. In this case, it did, but that fact is immaterial to the printed outcome.)

Before the execution of the line
   s = "remote"
"s" is a local variable which references the passed-in string object "local". After execution, the "s" variable references the local string object, "remote". Upon termination of the enclosing method function, the "s" variable falls out-of-scope and the "remote" string object gets garbage-collected.</description>
		<content:encoded><![CDATA[<p>Short answer:</p>
<p>t.name=&#8221;remote&#8221; alters the &#8220;t&#8221; object&#8217;s &#8220;name&#8221; attribute, whereas s=&#8221;remote&#8221; alters only the local s variable. The astring variable remains unchanged.</p>
<p>Long answer:</p>
<p>All variables (including functions&#8217; parameters) are references to objects. Assigning a variable merely changes the object to which the variable refers.</p>
<p>Modules, classes and functions are objects which, when nested, define hierarchies of namespaces. The . dot notation dereferences each level within the hierarchy by implicitly querying the   object&#8217;s attributes __dict__ using the key . The result of dereferencing is always an object.</p>
<p>At the line<br />
   t.name=’remote’<br />
in the example, &#8220;t&#8221; is a local variable (i.e., an implicit attribute of the &#8220;settime&#8221; method function object) referencing a passed-in object. The assignment sets that passed-in object&#8217;s &#8220;name&#8221; attribute to reference the local string object &#8220;remote&#8221;. (Note that this assignment occurs independently of whether or not the passed-in object had a &#8220;name&#8221; attribute previously. In this case, it did, but that fact is immaterial to the printed outcome.)</p>
<p>Before the execution of the line<br />
   s = &#8220;remote&#8221;<br />
&#8220;s&#8221; is a local variable which references the passed-in string object &#8220;local&#8221;. After execution, the &#8220;s&#8221; variable references the local string object, &#8220;remote&#8221;. Upon termination of the enclosing method function, the &#8220;s&#8221; variable falls out-of-scope and the &#8220;remote&#8221; string object gets garbage-collected.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ranen</title>
		<link>http://shiftmode.com/2008/02/python-class-confusion.html#comment-13105</link>
		<dc:creator>Ranen</dc:creator>
		<pubDate>Thu, 21 Feb 2008 05:07:31 +0000</pubDate>
		<guid>http://shiftmode.com/2008/02/python-class-confusion.html#comment-13105</guid>
		<description>Hi Brydon.

I found this helpful: http://www.goldb.org/goldblog/CommentView,guid,4eb92070-c279-44b3-ac2a-5d1c4f3e8115.aspx

"Alex is right that trying to shoehorn Python into a "pass-by-reference" or "pass-by-value" paradigm is misleading and probably not very helpful. In Python every variable assignment (even an assignment of a small integer) is an assignment of a reference. Every function call involves passing the values of those references."

and

It is important to understand mutable and immutable objects. Some objects, like strings, tuples, and numbers, are immutable.  Altering them inside a function/method will create a new instance and the original instance outside the function/method is not changed.  Other objects, like lists and dictionaries are mutable, which means you can change the object in-place.  Therefore, altering an object inside a function/method will also change the original object outside.</description>
		<content:encoded><![CDATA[<p>Hi Brydon.</p>
<p>I found this helpful: <a href="http://www.goldb.org/goldblog/CommentView,guid,4eb92070-c279-44b3-ac2a-5d1c4f3e8115.aspx" rel="nofollow">http://www.goldb.org/goldblog/CommentView,guid,4eb92070-c279-44b3-ac2a-5d1c4f3e8115.aspx</a></p>
<p>&#8220;Alex is right that trying to shoehorn Python into a &#8220;pass-by-reference&#8221; or &#8220;pass-by-value&#8221; paradigm is misleading and probably not very helpful. In Python every variable assignment (even an assignment of a small integer) is an assignment of a reference. Every function call involves passing the values of those references.&#8221;</p>
<p>and</p>
<p>It is important to understand mutable and immutable objects. Some objects, like strings, tuples, and numbers, are immutable.  Altering them inside a function/method will create a new instance and the original instance outside the function/method is not changed.  Other objects, like lists and dictionaries are mutable, which means you can change the object in-place.  Therefore, altering an object inside a function/method will also change the original object outside.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ranen</title>
		<link>http://shiftmode.com/2008/02/python-class-confusion.html#comment-13103</link>
		<dc:creator>Ranen</dc:creator>
		<pubDate>Thu, 21 Feb 2008 04:48:52 +0000</pubDate>
		<guid>http://shiftmode.com/2008/02/python-class-confusion.html#comment-13103</guid>
		<description>Hi Brydon.

I found this helpful:

http://www.goldb.org/goldblog/CommentView,guid,4eb92070-c279-44b3-ac2a-5d1c4f3e8115.aspx

"In Python every variable assignment (even an assignment of a small integer) is an assignment of a reference. Every function call involves passing the values of those references."

and

"It is important to understand mutable and immutable objects. Some objects, like strings, tuples, and numbers, are immutable.  Altering them inside a function/method will create a new instance and the original instance outside the function/method is not changed.  Other objects, like lists and dictionaries are mutable, which means you can change the object in-place.  Therefore, altering an object inside a function/method will also change the original object outside."</description>
		<content:encoded><![CDATA[<p>Hi Brydon.</p>
<p>I found this helpful:</p>
<p><a href="http://www.goldb.org/goldblog/CommentView,guid,4eb92070-c279-44b3-ac2a-5d1c4f3e8115.aspx" rel="nofollow">http://www.goldb.org/goldblog/CommentView,guid,4eb92070-c279-44b3-ac2a-5d1c4f3e8115.aspx</a></p>
<p>&#8220;In Python every variable assignment (even an assignment of a small integer) is an assignment of a reference. Every function call involves passing the values of those references.&#8221;</p>
<p>and</p>
<p>&#8220;It is important to understand mutable and immutable objects. Some objects, like strings, tuples, and numbers, are immutable.  Altering them inside a function/method will create a new instance and the original instance outside the function/method is not changed.  Other objects, like lists and dictionaries are mutable, which means you can change the object in-place.  Therefore, altering an object inside a function/method will also change the original object outside.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pat</title>
		<link>http://shiftmode.com/2008/02/python-class-confusion.html#comment-13101</link>
		<dc:creator>pat</dc:creator>
		<pubDate>Thu, 21 Feb 2008 02:40:25 +0000</pubDate>
		<guid>http://shiftmode.com/2008/02/python-class-confusion.html#comment-13101</guid>
		<description>makes sense to me (i think), the string (s) gets passed by value and the object (t) gets passed by reference - there's only one 'me'</description>
		<content:encoded><![CDATA[<p>makes sense to me (i think), the string (s) gets passed by value and the object (t) gets passed by reference - there&#8217;s only one &#8216;me&#8217;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
