I'm having trouble understanding why I can't seem to access a dict object of a class once the class instance is referenced through a dict of instances. If that makes sense at all ;)
I have a simple class containing only a dict called index.
class Node:
def __init__(self):
self.index = {}
I'm creating a dict of nodes by name, in this case the name is a number string.
INFILES = ["log.csv"]
INNODES = ["2","3"]
INPARAMS = ["v","g"]
nodes = {}
for nodestr in INNODES: #create dict of nodes
newnode = Node()
print nodestr
print newnode
print newnode.index
nodes[nodestr] = [newnode]
for n in nodes:
print n
print nodes[n]
print nodes[n].index
But when I print out the index after adding to the dict I get a reference to a list object not the original dict.
2
<myModule.Node instance at 0xb7e46bcc>
{}
3
<myModule.Node instance at 0xb7e46d0c>
{}
3
[<myModule.Node instance at 0xb7e46d0c>]
<built-in method index of list object at 0xb7e4622c>
2
[<myModule.Node instance at 0xb7e46bcc>]
<built-in method index of list object at 0xb7e4654c>
I must be missing something :(