Skip to content
Advertisement

Tag: subclass

Override a “private” method in Python

Consider a class with a “private” method such as: When I try to subclass Foo and override method __method, it can be seen that Foo.__method is still called, instead of MoreFoo.__method. What would be the way to override such a method? Answer The point of using the double-underscore name convention is to prevent subclasses from (accidentally) overriding the method. If

How to create a subclass in python that is inherited from turtle Module

So, i’m trying to learn python and every time i post a question here it feels like giving in… I’m trying to make my own class of turtle.Turtle. Gives the Traceback: AttributeError: ‘TurtleGTX’ object has no attribute ‘_position’. Which I then learn is a “private vairable” which according to the offical python tutorial i can mangle/override in my subclass TurtleGTX.

Subclass dict: UserDict, dict or ABC?

What’s the difference between UserDict, dict and ABC and which one is recommended? The docs seem to deprecate UserDict? Also it seems UserDict’s update() would use my setitem method whereas dict doesn’t? Which methods are really essential to override given I want custom setitem and getitem function? With ABCs I’d have to implement absolutely all methods since it provides no

Advertisement