Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #71709
| X-Received | by 10.58.41.39 with SMTP id c7mr4955211vel.25.1400371002324; Sat, 17 May 2014 16:56:42 -0700 (PDT) |
|---|---|
| X-Received | by 10.140.50.239 with SMTP id s102mr1560qga.7.1400371002213; Sat, 17 May 2014 16:56:42 -0700 (PDT) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!hl10no631061igb.0!news-out.google.com!qf4ni2017igc.0!nntp.google.com!c1no9331457igq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Sat, 17 May 2014 16:56:42 -0700 (PDT) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=134.109.114.9; posting-account=8TkBGgoAAAAujQCaKU4bU2rJUYDVARhu |
| NNTP-Posting-Host | 134.109.114.9 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <fce5a884-c9b0-4870-bec3-bb8ce16fa5a9@googlegroups.com> (permalink) |
| Subject | Can't figure out 'instance has no attribute' error |
| From | varun7rs@gmail.com |
| Injection-Date | Sat, 17 May 2014 23:56:42 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.lang.python:71709 |
Show key headers only | View raw
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?
File RW1:
class PHY_NETWORK:
def __init__(self, nodes, edges):
self.nodes = nodes
self.edges = edges
def addNode(self, node):
self.nodes.append( node )
def addEdge(self, edge):
self.edges.append( edge )
File RW3:
def createnetwork(graph):
doc = parse( args.paramFile )
noderef = []
num = 0
nodelist = doc.getElementsByTagName("node")
for node in nodelist:
noderef.append(node.getAttribute("id"))
proc = random.randint(3500, 5000)
stor = random.randint(7200, 8200)
switch = random.randint(7000, 10000)
num = num + 1
totaldemands = random.randint(1, 5)
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)))
linkid = 0
linklist = doc.getElementsByTagName("link")
for link in linklist :
linkid = linkid + 1
Source = link.getElementsByTagName("source") [0]
Destination = link.getElementsByTagName("target") [0]
Capacity = link.getElementsByTagName("capacity") [0]
SourceID = noderef.index(Source.firstChild.data) + 1
DestinationID = noderef.index(Destination.firstChild.data) + 1
graph.addEdge( PHY_LINKS( linkid, Source.firstChild.data, Destination.firstChild.data, DestinationID, SourceID, float(Capacity.firstChild.data) ))
global args
args = parser.parse_args()
samplenetwork = PHY_NETWORK([], [])
for i in range(1, 100):
createnetwork(samplenetwork)
exportXmlFile(samplenetwork, args.output, 'a' )
if __name__ == "__main__":
main(sys.argv[1:])
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'
The error that it give back is as above. I have the classes defined in RW1 file and I am importing the classes onto RW3 file and yet, It doesn't seem to work. I really am in need of your valuable suggestions. Thank You
Back to comp.lang.python | Previous | Next — 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