Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #71712
| Newsgroups | comp.lang.python |
|---|---|
| Subject | Re: Can't figure out 'instance has no attribute' error |
| References | <fce5a884-c9b0-4870-bec3-bb8ce16fa5a9@googlegroups.com> |
| From | "Rhodri James" <rhodri@wildebst.org.uk> |
| Organization | The Wildebestiary |
| Message-ID | <op.xf04rvvv5079vu@gnudebeest> (permalink) |
| Date | 2014-05-18 01:24 +0100 |
On Sun, 18 May 2014 00:56:42 +0100, <varun7rs@gmail.com> 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 <module>
> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Can't figure out 'instance has no attribute' error varun7rs@gmail.com - 2014-05-17 16:56 -0700
Re: Can't figure out 'instance has no attribute' error Ned Batchelder <ned@nedbatchelder.com> - 2014-05-17 20:16 -0400
Re: Can't figure out 'instance has no attribute' error "Rhodri James" <rhodri@wildebst.org.uk> - 2014-05-18 01:24 +0100
Re: Can't figure out 'instance has no attribute' error Gary Herron <gary.herron@islandtraining.com> - 2014-05-17 17:16 -0700
Re: Can't figure out 'instance has no attribute' error varun7rs@gmail.com - 2014-05-18 12:02 -0700
Re: Can't figure out 'instance has no attribute' error Chris Angelico <rosuav@gmail.com> - 2014-05-19 05:10 +1000
csiph-web