Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:error': 0.03; 'importing': 0.05; 'args': 0.07; 'attribute': 0.07; 'error:': 0.07; "subject:' ": 0.07; '"__main__":': 0.09; "'a'": 0.09; '[0]': 0.09; '__name__': 0.09; 'received:67.192': 0.09; 'received:67.192.241': 0.09; 'received:dfw.emailsrvr.com': 0.09; 'subject:instance': 0.09; 'suggestions.': 0.09; 'python': 0.11; 'def': 0.12; '[])': 0.16; '__init__,': 0.16; 'nodes': 0.16; 'proc': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'skip:f 30': 0.19; 'later': 0.20; 'header:User-Agent:1': 0.23; 'error': 0.23; '31,': 0.24; 'received:emailsrvr.com': 0.24; 'skip:l 30': 0.24; 'source': 0.25; 'received:(smtp server)': 0.26; 'switch': 0.26; 'defined': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; "doesn't": 0.30; 'friends,': 0.30; 'work.': 0.31; 'code': 0.31; 'doc': 0.31; 'gary': 0.31; 'indentation': 0.31; 'node': 0.31; 'file': 0.32; 'class': 0.32; '(most': 0.33; 'level.': 0.33; 'skip:_ 10': 0.34; 'skip:d 20': 0.34; 'could': 0.34; 'classes': 0.35; 'but': 0.35; 'really': 0.36; 'edge': 0.36; 'should': 0.36; 'two': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'skip:n 30': 0.60; 'subject:Can': 0.60; 'back': 0.62; 'email addr:gmail.com': 0.63; 'kind': 0.63; 'valuable': 0.63; 'skip:n 40': 0.81; 'destination': 0.91 X-Virus-Scanned: OK Date: Sat, 17 May 2014 17:16:46 -0700 From: Gary Herron User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Can't figure out 'instance has no attribute' error References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 81 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1400372803 news.xs4all.nl 2947 [2001:888:2000:d::a6]:34811 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:71713 On 05/17/2014 04:56 PM, 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? It's an indentation error: In the following the three function defs for __init__, addNode and addEdge should all be at the same indentation level. Instead, you have the later two defined *inside* the __init__. Gary Herron > > 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 > 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