I'd like to know what's the best way to organize a class in Python as checking on previous questions here I didn't find exactly what I needed. Let's say I have this class:
class A():
def __init__(self):
self.data = #A pandas dataframe I get from an online API
I have then many functions inside this class which I'd like to organize. All these functions will need the Dataframe contained in self.data as parameter.
I thought to create a subclass for every group of functions but I didn't find a way to then refer to self.data from inside the subclass.
I found then online that I could organize the functions in different modules. However how to I pass the Dataframe in self.data as parameter to the functions? Let's say function1 is defined as following:
def function1(self):
print (self.data)
If the function was defined inside the class, I could do this:
x = A()
x.function1()
and get the print without passing self.data as parameter. How would I do this if a function is defined in another module and I import it in the main class without passing self.data as parameter every time? Thanks in advance.
EDIT: If I do:
class A():
def __init__(self):
self.x = 1
self.b = self.B()
class B(A):
def print(self):
print(self.x)
I get an error saying "A is not defined"