inheritance

Why does defining new class sometimes call the __init__() function of objects that the class inherits from?

Why does defining new class sometimes call the __init__() function of objects that the class inherits from? Question: I’m trying to understand what actually happens when you declare a new class which inherits from a parent class in python. Here’s a very simple code snippet: # inheritance.py class Foo(): def __init__(self, *args, **kwargs): print("Inside foo.__init__") …

Total answers: 1

using class inheritance on tkinter python

using class inheritance on tkinter python Question: please help, I am trying to create a button on a tkinter window with the use of python class inheritance but it does not show the button. I am new to inheritance in python and not sure how do this. please see my code. thanks in advance from …

Total answers: 1

Python – Inherited methods break when overriding __init__

Python – Inherited methods break when overriding __init__ Question: I have a geometric base class ExtrudedSurface and a child class Cylinder, which is a ‘kind of’ extruded surface. The base class has a method to translate itself (not in-place) by constructing a modified version of itself. I would like to re-use this method by the …

Total answers: 1

Values grabbed through one class are not being passed to the inheriting class in PyQT5

Values grabbed through one class are not being passed to the inheriting class in PyQT5 Question: I am building a GUI for a hand tracking app using PyQT5. There are two windows: one ‘MainWindow’ which displays the camera view, and one called ‘Window 2’ which holds multiple checkboxes that correspond to actions that can be …

Total answers: 1

How to declare instance variables in abstract class?

How to declare instance variables in abstract class? Question: class ILinkedListElem: @property def value(self): raise NotImplementedError @property def next(self): raise NotImplementedError class ListElem(ILinkedListElem): def __init__(self, value, next_node=None): self.value = value self.next = next_node I wanna something like this. This abstract variables definition works for class vars, but not for instance I want to all instances …

Total answers: 1

Difficulty instantiating a subclass [object has no attribute]

Difficulty instantiating a subclass [object has no attribute] Question: I get two types of errors when I try to start or initiate the member function temp_controll from the subclass Temperature_Controll. The issue is that the while loops are started in a new thread. I am having trouble passing the modbus client connection to the member …

Total answers: 3

C-like forward declaration in python class

C-like forward declaration in python class Question: How would I properly do the following in python? class AnyType: def __init__(self, Type:Union[PrimitiveType, ComplexType]): self.Type = Type class PrimitiveType(AnyType): def __init__(self, Type): super().__init__(Type) class NestedType(AnyType): def __init__(self, Type): super().__init__(Type) NameError: name ‘PrimitiveType’ is not defined I know in C there is a forward declaration but how do …

Total answers: 1

How does inheritance of class variables work in Python?

How does inheritance of class variables work in Python? Question: I’m trying to get back to Python but I don’t get why the following code doesn’t work as intended. class Cat: age = 0 class Dog(Cat): pass Dog.age = 1 Cat.age = 2 print(Dog.age, Cat.age) My output is: 1 2 But why doesn’t Dog.age equals …

Total answers: 2