Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64396
| References | <8abb6a72-c258-4f08-a391-867d2680591d@googlegroups.com> |
|---|---|
| Date | 2014-01-21 21:47 +1100 |
| Subject | Re: use class in class |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5775.1390301245.18130.python-list@python.org> (permalink) |
On Tue, Jan 21, 2014 at 9:20 PM, Robert Voigtländer <r.voigtlaender@gmail.com> wrote: > 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 You're using the name Node to mean two different things. In the first line, you expect it to be the global name (which is the class), but on the second, you want to iterate over the node instances. That assigns to the name Node, which causes your problems. I recommend using a different name for the instances here, probably with a lower-case first letter. That would solve your problem _and_ make your code more readable. ChrisA
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