Is there a correct way to use the constructor arguments when I am creating other attributes? For example:
do I use shape=arg3.shape OR shape=self.arg3.shape when I am creating self.arg4?
import numpy as np
class MyClass:
def __init__(self, arg1, arg2, arg3=None, arg4=None):
self.arg1 = arg1
self.arg2 = arg2
if arg3 is None:
self.arg3 = np.array([[10, 10], [10, 10]])
else:
self.arg3 = arg3
if (arg3 is None) and (arg4 is None):
self.arg4 = np.ones(shape=(2,2))
elif arg4 is None:
print('Look at this case')
self.arg4 = np.ones(shape=self.arg3.shape)
# OR
self.arg4 = np.ones(shape=arg3.shape)
else:
self.arg4 = arg4
def print_args(self):
print(self.arg1)
print(self.arg2)
print(self.arg3)
print(self.arg4)
if __name__ == '__main__':
x = np.array([[25, 20], [20, 25]])
my_obj = MyClass(arg1=3, arg2=4, arg3=x)
my_obj.print_args()
I'm guessing both work the same based on the output, but I am looking for an answer explaining what the best practice would be if any and the OOP reasoning behind it.