I have two classes in a different file, and I want to pass list values from one to another, but it gives me an empty list; my code is very long, so that I will provide an example.
Example: file1.py
class a:
def __init__ (self):
self.result = []
def set_result(self, result_a):
self.result.append(result_a)
file2.py
class b:
def add_value_to_list():
file1.a().set_result("add_value")
The code is to understand the idea. I want self.result returned all values that I added by using add_value_to_list()
I want self.result = ["add_value"] that I passed from add_value_to_list()
CodePudding user response:
there are two problems with this, the first was fixed with an edit, but the second may be more structural
missing
selfarg to method
methods normally need to be passed this as their first argument to access other methods and data attached to their instance of the classclass
bcreates a new instance ofaevery timeadd_value_to_listis called (a()), instead it should probably create a single instance ofaduring its init and refer to it on someself.
