python中 **kwargs 的应用

fanhuasijin 2020-02-17

def __init__(self, **kwargs):
        allowed_kwargs = {‘name‘, ‘logging‘}
        for kwarg in kwargs.keys():
            assert kwarg in allowed_kwargs, ‘Invalid keyword argument: ‘ + kwarg
        name = kwargs.get(‘name‘)

这里应用assert来给出指定的keys

相关推荐