Are there some way to use the class attribute from parent inside child but do not inherit it? This is the example code. The point is that I’ll create many instances of Cycle class and it’s running out of memory because the all_cycles attribute has much more items than the example, but it’s fixed to all instances of Cycle. How
Tag: oop
EXP system for adjusting instance attributes in Python (text-based RPG)
I have recently begun programming in Python and decided to start my journey by writing a text-based RPG. The issue that I have now stumbled upon is that I was trying to create an EXP-system to make the character’s stats dependent on their level, but it doesn’t seem to work the way I want it to. While I have achieved
Kivy Python: confused with class and instance methods
I was trying kivy and while I was accessing class variables, I was forced to use ‘self’ for class variables or else it was producing error. This is the kivy code I was using. Below is the main.py code where I have confusion: This code works. Here I am using class variables and accessing them from ‘self’. According to me
Segmentation fault in destructor with Python
I have made a class to represent my led strip, and I would like to switch off the strip when I stop it (aka when the program stops and the object is destroyed). Hence, as I would do in C++, I created a destructor to do that. But it looks like Python call it after it destroyed the object. Then
Defining functions dynamically does not work inside class objects?
In my current project, I am constructing functions dynamically by assembling a string, executing this string, then appending the resulting functions to a list. This works well inside a console, even when looped, but strangely does not work when I attempt to do the same thing inside a class object. Do you know why, and how I could get this
How to use __get__ and __set__ (python descriptors)
I’m new to using descriptors and I think I have a good understanding on how they work but I have come across a problem and i’m not sure how to fix it. Code Output Im trying to make bar a constant for testing purposes, I know about the property decorator but I prefer using descriptors. First I print out the
How to add background image in Tkinter using OOP concept?
I am new to object oriented python programming. Currently I am using Python 3. I want to create an app which has multiple pages. I am able to navigate between pages but find it difficult to add image in the background. Please note I don’t want to know how to background image in tkinter as I am already able to
Making child class inherit methods from parent in tkinter
I’m new to Tkinter and OOP. I’ve been trying to make child class inherit some methods from parent class because I’d have repeated code if I didn’t do it like that. But I’ve stumbled on a problem, caused probably by my limited knowledge of Tkinter and OOP. Here is my code: (it’s really simplified, but it is enough to solve
GCD implementation of fraction addition not working properly
I am following the Runestone Academy Python3 course and tried to implement ‘addition’ feature for fractions using Class but I am getting error. When I am not using GCD implementation, the code is running fine Here is my code: This is the error I am getting: I also tried with this variation but same error: Answer The gcd method should
Python best practices — can I set an object attribute to call a class method?
I am building a tool to query all DNS records for a hostname. Each hostname will create a ScanObject object, which will call another module to do the queries upon instantiation. I create class methods so that I can just pull records I need instead of all the records. Therefore, these methods need to refer to the dictionary that contains