[Tutor] *args, **kwargs

Alan Gauld alan.gauld at freenet.co.uk
Sun Jan 2 00:01:45 CET 2005


> class SomethingLikeThis:
>     def __init__(self, **kwargs):
>         self.kwargs = kwargs
>
>     def show(self):
>         for k in self.kwargs.keys():
>             v = selfkwargs.get(k)

is this a typo in the mail or a real error?
              v = self.kwargs.get(k)

>             print v
>
> I'm probably misunderstanding the purpose of *args and **kwargs
totally.

Don't think so, here's my session:

>>> class C:
...   def __init__(s,**kw):
...     s.kw = kw
...   def show(s):
...     for k in s.kw.keys():
...       print s.kw[k]
...
>>> c = C(a=42, b=54)
>>> c.show()
42
54
>>>

HTH,

Alan G.



More information about the Tutor mailing list