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 to do this? class Parser: token_functions =… Read More Pass self automatically in lambda function?
I was making a new path for pages on my site and was trying to figure out how to path to my stylesheet and images cleanly. Here’s an element that shows my problem: <link rel="stylesheet" href="/src/styles.css"> My local copy of my site is hosted here at "E:/Documents/WEBSITE", the local page I’m trying to link the… Read More relative src and href paths work live but not local
As we all know, if you have a function like this: def foo(): foo() The function will call itself 1000 times and then you get a RecursionError exception. But what if you had a thousand and one different functions that call each other? i.e. a() calls b() calls c() and so on. Would you get… Read More Are there separate call tree depths for recursive and non-recursive calls?
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: class DataBase_Management(object): def __init__(self): self.result =  def make_dict_items(self): with open("Items2.csv") as… Read More How to Reference List of Dicitionaries from One Class to Another?
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) plt.scatter(X,Y, color=’black’) plt.plot(X, clf.predict(X)) #np.size(X) I have… Read More Linear regression (Gradient descent) single feature
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 internet but had no luck. Here is an… Read More Variables inside constructor without "self" – Python
I have a file file_calling_class.py that needs to access the prediction value from another python module in file_with_class.py. However, I do not know how to access the prediction. The function alone works fine if it is the only script but if I want to pass the budget value from file_calling_class.py to file_with_class.py by using self… Read More How to access prediction from another python module?
I want to print(read or use) the changing variable self.tt in B().check() while class A is changing self.tt, is it any way to do it or other better solution to achieve the task? class A: def __init__(self): self.tt = 0 def change_tt(self): for i in range(100000000): self.tt += 1 sleep(1) class B(): def __init__(self): self.x… Read More How can I access the changed variable from another class
According to Rust Lang Programming Book, we know that: The &self is actually short for self: &Self However, from the example below (fn get_name), we wrote self: &Self, but self is not a reference but the object itself according to the error message. Why isn’t self a reference in this case? What is the ampersand… Read More Rust: Why isn't "self" a reference when "self: &Self"?