Nov-25-2022, 11:42 AM
Hi,
i get confused when i build my class stuctures. I got 2 questions.
1.
Since all of my classes will use the some base attributes i collected them in a base class.
When i call my constructor for k1 , I get
"unexpected keyword arg" error for the attribute "material" - which is derived from its base class.
How to avoid this?
2.
i am not sure if my style is pytonic the way as below.
Normally i have many more attributes (~up to 20) in each class. Maybe there is a better method.
i get confused when i build my class stuctures. I got 2 questions.
1.
Since all of my classes will use the some base attributes i collected them in a base class.
When i call my constructor for k1 , I get
"unexpected keyword arg" error for the attribute "material" - which is derived from its base class.
How to avoid this?
2.
i am not sure if my style is pytonic the way as below.
Normally i have many more attributes (~up to 20) in each class. Maybe there is a better method.
class MyClass1(MyBaseClass):
def __init__(self,
name=None,
length=None,
height=None,
color=None,
) -> None:
super().__init__()
self.__name = name
self.__length = length
self.__height = height
self.__color = color
class MyClass2(MyBaseClass):
def __init__(self,
name=None,
vol=None,
weight=None,
dense=None,
) -> None:
super().__init__()
self.__name = name
self.__vol = vol
self.__weight = weight
self.__dense = dense
class MyBaseClass(metaclass=ABCMeta):
def __init__(self,
material=None,
origin=None,
manufacturer=None,
) -> None:
self.__material = material
self.__origin = origin
self.__manufacturer = manufacturer
k1 = MyClass1(name=get_name(input_data),
length=get_length(input_data),
height=get_height(input_data),
color=get_color(input_data),
material=get_basis_info_material(input_data),
origin=get_basis_info_origin(input_data),
manufacturer=get_basis_info_manufacturer(input_data),
)
