attribute assignment effects all class instances
anon
anon at anon.net
Fri Sep 10 15:51:33 EDT 2004
In article <n482k05n00ecb8ajbgg7gs3g6u8s44sv7b at 4ax.com>, Dennis Lee
Bieber <wlfraed at ix.netcom.com> wrote:
> On Thu, 09 Sep 2004 16:59:24 -0700, anon <anon at anon.net> declaimed the
> following in comp.lang.python:
>
>
> > In module node:
> >
> > class Node:
> >
> >
> >
> > Here's the wierd thing, in another module I have:
> >
> > node.adjacent[left] = y
> >
> > where node is an instance of the Node class. This statement assigns
>
> I'd recommend some name changes somewhere... Too many "nodes"
> here...
>
> Your "another module" had to have done an "import node" (since
> that is the name you claim at the top). You then had to perform
> something like: "node = node.Node()" to create the instance, but that
> would also supersede the module name node...
Dennis--
I actually imported the module as "from node import *", so I haven't
run into a name conflict (apparently). Though I see your point for
naming things differently.
Peter--
Sorry for my miswording of assignment to shared class data.
Everyone--
Thank you very much for your assistance. I was unaware that the
default arguments were created only once and then reused for each
instance. The situation makes complete sense now.
--Greg
More information about the Python-list
mailing list