Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64406
| From | Dave Angel <davea@davea.name> |
|---|---|
| Subject | Re:use class in class |
| Date | 2014-01-21 07:04 -0500 |
| Organization | news.gmane.org |
| References | <8abb6a72-c258-4f08-a391-867d2680591d@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5781.1390305745.18130.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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