self

`TypeError: missing 1 required positional argument: 'self'` Whitebox tools

`TypeError: missing 1 required positional argument: 'self'` Whitebox tools Question: I am attempting to use whitebox geospatial tools to analyze .tif files. Any whitebox tool I run however, raises the error: TypeError: missing 1 required positional argument: ‘self’. I understand that this is a well-documented error within the stack overflow community, however, the way I …

Total answers: 1

Pass self automatically in lambda function?

Pass self automatically in lambda function? Question: Is there a way to automatically pass self to a lambda function in a class? I know I can pass self in the __init__ function but then I’m redefining token_functions for every instance of Parser. token_functions never changes so this seems quite inefficient. Is there a better way …

Total answers: 1

Are class variables accessed via self used as iterables good practice/pythonic?

Are class variables accessed via self used as iterables good practice/pythonic? Question: Is it appropriate to use a class variable accessed with self as an iterable in a loop? The following python code is valid and produces the expected result ("1, 2, 3") but it feels wrong somehow: class myClass(): foo = None def myfunc(self): …

Total answers: 1

cv2 onMouse() has a missing argument when using importlib to create a class at runtime

missing argument when using importlib to create a class at runtime Question: I want to load a Python file (module) dynamically when the user inputs the filename (here for example: RegionOfInterest.py). In the file will be one class (here: RegionOfInterest). All classes have a method with the same name (here: start) which I want to …

Total answers: 1

self in Python references to variable rather than the class

self in Python references to variable rather than the class Question: So, I’m trying to code an observer pattern in Python. Main method: import Subject as Subj import ConcreteStateA as Obs Newsletter = Subj.Subject Paul = Obs Sara = Obs Julien = Obs print(Paul) print(Sara) Newsletter().addObserver(Paul) Newsletter().addObserver(Sara) Newsletter().addObserver(Julien) Newsletter().notifyObservers("Bald ist Weihnachten!") Newsletter().removeObserver(Paul) Newsletter().notifyObservers("Der Nikolaus steht …

Total answers: 1

How to Reference List of Dicitionaries from One Class to Another?

How to Reference List of Dicitionaries from One Class to Another? Question: I am currently working on an inventory system and trying to implement a class that serves as a "fast fact finer" for my database, which is managed by my Database Management class. The csv file looks like this: I have the following code: …

Total answers: 1

Linear regression (Gradient descent) single feature

Linear regression (Gradient descent) single feature Question: import numpy as np import matplotlib.pyplot as plt from sklearn import linear_model class gradientdescent: def fit(self,X,Y): lr=0.01 m=5 b=0 m_gradient=0 for _ in range(1000): m_gradient= (lr*(np.sum((m*X+b-Y)*X))/(np.size(X))) b_gradient= (lr*(np.sum(m*X+b-Y))/(np.size(X))) self.m=m-m_gradient #this part is giving me conflicting results self.b=b-b_gradient #and this part def predict(self,X): return self.m*X+self.b X=np.array([1,2,3,4,5,6,7,8]) Y=np.array([1,2,4,4,5,7,8,8]) clf=gradientdescent() clf.fit(X,Y) …

Total answers: 1

Variables inside constructor without "self" – Python

Variables inside constructor without "self" – Python Question: I am trying to understand whether declaring variables inside constructors is an ok practice. I only need these variables inside the constructor. I am asking this because most of the times I’ve seen constructors they only contained self variables. I’ve tried to find an answer on the …

Total answers: 2