oop

Struggling to print objects in Python using list comprehension

Struggling to print objects in Python using list comprehension Question: I am learning Python for the first time and am trying to build a full fledged object oriented program, based on a childhood nursery rhyme/game about counting fists (Bubblegum Bubblegum in a Dish…) I have a class/Player object, which has fists as an attribute. There …

Total answers: 1

How can a child class inherit a class method from its parent that gets a class variable from the child in python?

How can a child class inherit a class method from its parent that gets a class variable from the child in python? Question: I have a code here where I define a parent class with class methods and class variables: class Parent: var1 = ‘foo’ var2 = ‘bar’ def getVar1Var2AsString(self): return f'{Parent.getVar1()}_{Parent.getVar2()}’ @classmethod def getVar1(cls): …

Total answers: 3

Chaining multiple class arguments

Chaining multiple class arguments(tried many ways) Question: How should I initialize multiple class arguments that came as chain and then calculate sum of them? I’ve tried many ways but NOTHING Do you have any idea? >>> Chain(2.5)(2)(2)(2.5) # sum 9 >>> Chain(3)(1.5)(2)(3) # sum 9.5 Asked By: Harez || Source Answers: In general, you’ll want …

Total answers: 1

Python – create wrapper function for SQL queries

Python – create wrapper function for SQL queries Question: In my project I have lots of functions that carry out SQL queries. These queries include SELECT, UPDATE, INSERT etc… When writing functions for SELECT queries for example, I write the same structure of code in every single function. e.g. def generic_select_function(self): result = self.cursor.execute(""" SQL …

Total answers: 1

How do I print class name in a method?

How do I print class name in a method? Question: I made a method and called onto it with super() but I do not know how to write the name of the class in a print statement! from abc import ABC, abstractmethod class Clothing(ABC): @abstractmethod def desc(self): pass class Shirt(Clothing): def desc(self): x = input(‘Enter …

Total answers: 1

Return class object after changing object variables

Return class object after changing object variables Question: Im new to OOP in Python (and in general) and wondering about the correct way to change object variables. Since Python cant return void i need to return something when an object variable has changed. class classA: var_a = 1 var_b = 1 def changeSomething(classAObj): classAObj.var_a = …

Total answers: 1

How create task with celery in django? POO issue?

How create task with celery in django? POO issue? Question: I’m trying to set up a task with Django and Celery. The Celery and Django configuration is okay, nothing to report on that side. However, I have a problem, I think with the writing, of my code in OOP. I can’t locate where the problem …

Total answers: 1

Python Design Question – Concrete classes with different signature

Python Design Question – Concrete classes with different signature Question: I have two classes with similar methods; however, there are some different mandatory parameters in one class. e.g. class NamespaceScoped: def get_object(self, name, namespace): pass def delete_object(self, name, namespace): pass class ClusterScoped: def get_object(self, name): pass def delete_object(self, name): pass I need to create an …

Total answers: 1

Continue executing function

Continue executing function Question: When closing an instance of the ChildWindow class, which was called from another instance of MainWindow, the code does not continue to be executed. I noticed that only when the MainWindow instance is closed does it continue to run. In general, it has a cumulative property, so the number of times …

Total answers: 1