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 theCarSpecs
class 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
, andtype
as 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
, andtype
as 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
, andtype
as 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...