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


Groups > comp.lang.python > #64406

Re:use class in class

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'assignment': 0.07; 'error:': 0.07; 'lines,': 0.07; 'method.': 0.07; 'none,': 0.07; '__init__': 0.09; 'line:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'referenced': 0.09; 'works.': 0.09; 'def': 0.12; 'wrote': 0.14; '0))': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:class': 0.16; 'exception': 0.16; 'variable': 0.18; 'coding': 0.22; 'print': 0.22; 'error': 0.23; 'class.': 0.26; 'purposes': 0.26; 'header:X -Complaints-To:1': 0.27; 'chris': 0.29; 'robert': 0.30; 'especially': 0.30; 'node': 0.31; 'class': 0.32; 'another': 0.32; 'actual': 0.34; 'could': 0.34; 'problem': 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'really': 0.36; 'hi,': 0.36; 'should': 0.36; 'error.': 0.37; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; "you're": 0.61; 'name': 0.63; 'such': 0.63; 'different': 0.65; 'within': 0.65; 'subject::': 0.85
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re:use class in class
Date Tue, 21 Jan 2014 07:04:31 -0500 (EST)
Organization news.gmane.org
References <8abb6a72-c258-4f08-a391-867d2680591d@googlegroups.com>
X-Gmane-NNTP-Posting-Host dpc6744192108.direcpc.com
X-Newsreader PiaoHong Usenet NewsReaders 1.36
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.5781.1390305745.18130.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1390305745 news.xs4all.nl 2903 [2001:888:2000:d::a6]:32982
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:64406

Show key headers only | View raw


 Robert Voigtländer <r.voigtlaender@gmail.com> Wrote in message:
> Hi,
> 
> I have a problem using a class object within another class.
> It is about the line:
> 
> self.openlist.append(Node(self.start, None, 0, 0))
> 
> If I use it in __init__ it works. If I use it in calcRoute(self) I get the following error:  local variable 'node' referenced before assignment The error occures in AMap.calcRoute()
> 
> Where is my mistake?

Chris has addressed your coding error.  Within a function/method, 
 you really should use a name for just one purpose,  and
 especially if one of the purposes is global.

But you have a different problem as well. You're describing an
 exception by retyping one of its lines, rather than using
 copy/paste of the whole thing. The actual error message could not
 have said "node", as there's no such name in the method.
 
> 
> 
> 
>         
>     def calcRoute(self):
>         self.openlist.append(Node(self.start, None, 0, 0))
>         for Node in self.openlist: print Node.pos, Node.parent, Node.g, Node.h, Node.f
> 

-- 
DaveA

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


Thread

use class in class Robert Voigtländer <r.voigtlaender@gmail.com> - 2014-01-21 02:20 -0800
  Re: use class in class Chris Angelico <rosuav@gmail.com> - 2014-01-21 21:47 +1100
    Re: use class in class Robert Voigtländer <r.voigtlaender@gmail.com> - 2014-01-21 03:11 -0800
  Re:use class in class Dave Angel <davea@davea.name> - 2014-01-21 07:04 -0500
    Re: use class in class Robert Voigtländer <r.voigtlaender@gmail.com> - 2014-01-21 07:24 -0800

csiph-web