use class in class

Dave Angel davea at davea.name
Tue Jan 21 07:04:31 EST 2014


 Robert Voigtländer <r.voigtlaender at 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




More information about the Python-list mailing list