Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #71710

Re: Can't figure out 'instance has no attribute' error

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; 'insert': 0.05; 'attribute': 0.07; 'definitions': 0.07; "subject:' ": 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'spaces': 0.09; 'subject:instance': 0.09; 'suggestions.': 0.09; 'python': 0.11; 'def': 0.12; '__init__,': 0.16; 'nodes': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'tab': 0.16; 'tabs': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'file,': 0.19; 'skip:f 30': 0.19; 'header:User-Agent:1': 0.23; 'error': 0.23; '31,': 0.24; 'received:comcast.net': 0.24; 'replace': 0.24; 'class.': 0.26; 'defined': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; "doesn't": 0.30; 'characters': 0.30; 'friends,': 0.30; 'work.': 0.31; 'code': 0.31; 'node': 0.31; 'file': 0.32; 'class': 0.32; '(most': 0.33; 'skip:_ 10': 0.34; 'could': 0.34; 'display': 0.35; 'classes': 0.35; 'editor': 0.35; 'but': 0.35; 'really': 0.36; 'edge': 0.36; 'in.': 0.36; 'sometimes': 0.38; 'thank': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'subject:Can': 0.60; 'back': 0.62; "you've": 0.63; 'email addr:gmail.com': 0.63; 'kind': 0.63; 'valuable': 0.63; 'eight': 0.74
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Ned Batchelder <ned@nedbatchelder.com>
Subject Re: Can't figure out 'instance has no attribute' error
Date Sat, 17 May 2014 20:16:01 -0400
References <fce5a884-c9b0-4870-bec3-bb8ce16fa5a9@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host c-50-133-228-126.hsd1.ma.comcast.net
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.5.0
In-Reply-To <fce5a884-c9b0-4870-bec3-bb8ce16fa5a9@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.10101.1400372176.18130.python-list@python.org> (permalink)
Lines 48
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1400372176 news.xs4all.nl 2928 [2001:888:2000:d::a6]:55215
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:71710

Show key headers only | View raw


On 5/17/14 7: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?
>
> 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 )
>
...
>
>
> 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
>

You've set your editor to display tabs as 4 spaces, but then you've 
sometimes used tabs in your file, and sometimes 4 spaces.  Look at how 
your code is indented in your post: the addNode and addEdge definitions 
are indented with tab characters instead of spaces, so Python thinks 
they are eight spaces in.  This makes them defined inside of __init__, 
rather than as part of your class.

Set your editor to insert spaces when you use the Tab key, and set it to 
use 4-space indents.  Then find all the tab characters in your file and 
replace them with the proper number of spaces.

-- 
Ned Batchelder, http://nedbatchelder.com

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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