oop

module has no attribute OOP in python

module has no attribute OOP in python Question: I’m very new to OOP in python. I wrote a python script which takes an input file and plots some data from it. Now I want to make the same plots for several different data files, so I thought I’d make my script into a class. This …

Total answers: 1

applying Singleton to Spotipy throws error

applying Singleton to Spotipy throws error Question: Spotipy’s object needs to be passed a credential kw arg my code: import spotipy class Spoti2(spotipy.Spotify): spoty_obj = None @classmethod def __new__(cls, client_credentials_manager): if cls.spoty_obj is None: cls.spoty_obj = super().__new__(cls) print(‘se creo instancia’) return cls.spoty_obj but i get the error: Spoti2.__new__() got multiple values for argument ‘client_credentials_manager’ however, …

Total answers: 1

Why can't I call the functions within the class?

Why can't I call the functions within the class? Question: I just started Python OOP. I have to build a simple class and function, but I don’t understand why it works in one case, but doesn’t in the other. class Digital_signal_information: def __init__(self, signal_power: float, noise_power: float, n_bit_mod: int): self.signal_power = signal_power self.noise_power = noise_power …

Total answers: 2

Solving the problems in working with Python OOPs

Solving the problems in working with Python OOPs Question: I a trying to understand the Python OOP. I have came across the following errors; can someone suggest me the sources of the following errors and how to rectify them? Code: class Class1(object): def method_1(self, root): if root == None: return 0 # Why do I …

Total answers: 1

What is the need to define a function to return a class's attribute?

What is the need to define a function to return a class's attribute? Question: I came across some code like this class Student(Person): def __init__(self, age): self.age = age def get_age(self): return self.age Could you please explain the purpose of the function get_age()? If we want to know a student’s age, can’t we simply do …

Total answers: 1

trying python tkinter creating widgets with classes (frame)

trying python tkinter creating widgets with classes (frame) Question: I am trying to create custom widgets with classes. I have one class, called CustomWidgets inside it, I have method for creating Frame object, then configure its side key with config method, but it gives an error. code; from tkinter import * from tkinter import ttk …

Total answers: 1

how to use super().__init__() method for 2 or more classes?

how to use super().__init__() method for 2 or more classes? Question: Here I have provided an example to illustrate my problem when a class inherits from 2 classes, then the super method only calls the constructor of the first inherited class. import inspect class A : def __init__(self): self.atr1 = ‘Foo1’ class B : def …

Total answers: 1

implement class method based on instance variable (OOP)

implement class method based on instance variable (OOP) Question: i am new to oop. i want to create objects that have a method which depends on the instance variables. class cases: def __init__(self, a): self.a = a def f1(self, x): return x def f2(self, x): return 100*x if self.a < 3: self.x = f1 else: …

Total answers: 1