[MEMO] Pythonの可変引数
2008.06.01 Sunday 01:43
ソース
class t1(object):
  def __init__(self, a="test", b="test2", x="test3",):
    print "[t1] a=%s, b=%s, x=%s" % (a,b,x)
class t2(t1):
  def __init__(self,*arg,**kw):
    print "[t2]", arg, kw
    super(t2,self).__init__(*arg, **kw)
u = t2("value1", x="value2")
実行結果
[t2] ('value1',) {'x': 'value2'}
[t1] a=value1, b=test2, x=value2
*argと**kwの両方が必要.
Comments