It is common to find several apis that make use of KeyWordArgument
of python. My question is how to use this refuse for object attributes.
Sometimes when I use an API and I pass a parameter named param=True
and the class I'm instantiating does not have an attribute with that name, I get an exception stating that the class does not have a property with that name, for example:
>>> from gi.repository import Gtk
>>> a = Gtk.Button(label='Um botao')
>>> z = Gtk.Button(labelll='Um botao')
TypeError: gobject GtkButton doesn't support property 'labelll'
Question, how do I implement this in my classes? Another feature is also that the user can choose which parameters to pass, and those that he does not inform have default values.
The way I found it to achieve this is to set default values as in: def __init__(self, paran1=True, paran2=False, paran3='anything')
But how do I achieve the same effect using: def __init__(self, **kwargs)
?