[Tutor] dictionaries, objects and scoping...

John Morris jrmorrisnc at gmail.com
Tue Jan 22 03:36:48 CET 2008


So this seems like it will make scope/namespaces a bit interesting...

Any good references on why this is this way?
I.e., why assignment passes across scopes instead of copy.
Or is it just explicit versus implicit?



On Jan 21, 2008 9:32 PM, John Fouhy <john at fouhy.net> wrote:

> On 22/01/2008, John Morris <jrmorrisnc at gmail.com> wrote:
> > I thought each class got it's own namespace and this sharing of mutable
> > objects is confusing me.
>
> Each class gets its own namespace, but names are different from
> objects.  For example:
>
> >>> x = [1, 2, 3]
> >>> y = x
> >>> y.append(4)
> >>> x
> [1, 2, 3, 4]
>
> In this case, x and y are both different names for the same object.
> Classes increase the name space, but they don't change the fact that
> in python, assignment is just giving something a new name.
>
> --
> John.
>



-- 
John Morris
jrmorrisnc at gmail.com
"Do nothing which is of no use." -- Miyamoto Musashi
<a href="http://profile.mygamercard.net/nerdality">
<img src="http://card.mygamercard.net/gbar/abyss/nerdality.gif" border=0>
</a>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080121/ee28e7d7/attachment-0001.htm 


More information about the Tutor mailing list