Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!rt.uk.eu.org!news.roellig-ltd.de!open-news-network.org!cyclone01.ams2.highwinds-media.com!news.highwinds-media.com!voer-me.highwinds-media.com!peer01.am1!peering.am1!npeersf04.am4!fx22.am4.POSTED!not-for-mail Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes Newsgroups: comp.lang.python Subject: Re: Can't figure out 'instance has no attribute' error References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Rhodri James" Organization: The Wildebestiary Message-ID: User-Agent: Opera Mail/12.16 (Linux) Lines: 54 NNTP-Posting-Host: 81.97.70.240 X-Complaints-To: http://netreport.virginmedia.com X-Trace: 1400372697 81.97.70.240 (Sun, 18 May 2014 00:24:57 UTC) NNTP-Posting-Date: Sun, 18 May 2014 00:24:57 UTC Date: Sun, 18 May 2014 01:24:57 +0100 X-Received-Body-CRC: 3010337470 X-Received-Bytes: 2818 Xref: csiph.com comp.lang.python:71712 On Sun, 18 May 2014 00:56:42 +0100, wrote: > Hello Friends, > > I am working on this code but I kind of get the same error over and over > again. Could any of you help me fix this part of the error? Shuffling your post around to make an explanation easier, the traceback is: > srva@hades:~$ python RW3.py --output topology.xml --xml germany50.xml > Traceback (most recent call last): > File "RW3.py", line 157, in > main(sys.argv[1:]) > File "RW3.py", line 152, in main > createnetwork(samplenetwork) > File "RW3.py", line 31, in createnetwork > graph.addNode(PHY_NODES( node.getAttribute("id"), int(num), > float(xCoordinates.firstChild.data), > float(yCoordinates.firstChild.data), float(proc), float(stor), > float(switch), int(totaldemands))) > AttributeError: PHY_NETWORK instance has no attribute 'addNode' So Python thinks that PHY_NETWORK has no "addNode", but you do. Do you perchance have the tab width in your editor set to 4? I ask, because I imagine that you see this: > File RW1: > class PHY_NETWORK: > def __init__(self, nodes, edges): > self.nodes = nodes > self.edges = edges > def addNode(self, node): > self.nodes.append( node ) [snippety snip] I however saw your post like this: > File RW1: > class PHY_NETWORK: > def __init__(self, nodes, edges): > self.nodes = nodes > self.edges = edges > def addNode(self, node): > self.nodes.append( node ) [snippety snip] I've replaced the tabs with spaces to make it clearer. Basically, you've got a mix of tabs and spaces, which is always a bad idea, and as a result Python thinks that addNode is an attribute of PHY_NETWORK.__init__, not of PHY_NETWORK. You need to go through and replace all your tab characters with four spaces, and stop using tabs. -- Rhodri James *-* Wildebeest Herder to the Masses