Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - shantytown

Pages: [1]
1
Python / Question on inheritance
« on: September 21, 2014, 11:02:00 pm »
class MyRectangleShape(sfml.graphics.RectangleShape):
        def __init__(self):
                print('Output: ' + str(self.size))

box = MyRectangleShape()

Code: [Select]
Output: 0.0x, 0.0y
Why is RectangleShape's constructor implicitly called here? self should not have the attribute size without explicitly calling RectangleShape.__init__(). The reason this is significant is because this will cause all kinds of problems with the way I want to expand this class. Python isn't supposed to work that way. The only way I can imagine this would be intentional is if there is some metaprogramming causing it, and I don't know much about that.

Tried in Python 2.7.7 and 3.2.5. Same behavior in both.

Until I understand the problem, I guess I'll just stick to composition.

Pages: [1]