Basic Usage

Processing **kwargs in a class.

KwargsHelper class assigns attributes to existing class instance if they are missing. Each key in **kwargs is transformed into an attribute name and that attribute name is assigned to current instance of class if it does not already exist. Be default attribute names is the key name with _ appended. See Figure 2

**kwargs values are assigned to attribue that match keys.

Use KwargsHelper class to process **kwargs in a class.

Figure 1
from kwhelp import KwargsHelper

class MyClass:
    def __init__(self, **kwargs):
        kw = KwargsHelper(self, {**kwargs})
        kw.auto_assign()

>>> myclass = MyClass(speed=123)
>>> print(myclass._speed)
123

In the following example attribute names are transformed to match the key name. This is done by setting field_prefix to empty string in constructor. See Also: KwargsHelper.field_prefix

Figure 2
from kwhelp import KwargsHelper

class MyClass:
    def __init__(self, **kwargs):
        kw = KwargsHelper(originator=self, obj_kwargs={**kwargs}, field_prefix='')
        kw.auto_assign()
>>> myclass = MyClass(speed=123)
>>> print(myclass.speed)
123