Defining base classes
We will now start building the code required for the case study.
Let’s start by developing a metaclass named CarSpecs. This class will have the following structure:
- The
__new__of theCarSpecsclass will perform the following tasks:- If the attribute of the input class is an integer, then add the attribute name in title case as
feature, the value in string format asinfo, andtypeas numeric. - If the attribute of the input class is a string, then add the attribute name in title case as
feature, the value in string format asinfo, andtypeas varchar. - If the attribute of the input class is a Boolean, then add the attribute name title case as a
feature, the value in string format asinfo, andtypeas Boolean. - If not, the actual attribute will be returned as such.
- If the attribute of the input class is an integer, then add the attribute name in title case as
Let’s now look at the definition of CarSpecs:
from abc import ABC, abstractmethod class CarSpecs(type): Â Â Â Â def __new__(classitself, classname, baseclasses...