On Feb 4, 4:45 pm, "Mizipzor" <[EMAIL PROTECTED]> wrote: > I have some troubles with a member variable that seems to be missing > in a class. In short, heres what I do; class A is the parent class, B > inherits from A and C inherits from B (hope I used the right words > there). Now, I create an instance of C, which calls A's __init__ which > in turn creates all the member variables. Then I call C.move() (a > function defined in A), but then, one of the variables seems to have > become 'NoneType'. > > The code can be found here (Ive taken away unnecessery > stuff):http://pastebin.com/875394 > > The exact error is (which occur on line 15 in the pasted code): > TypeError: unsupported operand type(s) for *: 'NoneType' and 'float' > > Any comments are welcome. :)
Here's a suggestion: use new-style classes. Have _BaseEntity inherit from object, allows you to use super for invoking methods on super classes. Instead of: class Entity(_BaseEntity): def __init__(self, type, x = 0, y = 0): _BaseEntity.__init__(self, type, x, y) You enter: class Entity(_BaseEntity): def __init__(self, type, x = 0, y = 0): super(Entity,self).__init__(type, x, y) This makes it easier to update your inheritance hierarchy later. New- style classes have other benefits too. As for your NoneType problem, try adding "print self._direction" to the end of _BaseElement.__init__. -- Paul -- http://mail.python.org/mailman/listinfo/python-list