faqts : Computers : Programming : Languages : Python : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 3 people (100%) answered Yes
Recently 2 of 2 people (100%) answered Yes

Entry

How do I pass on keyword arguments in a function?

Oct 31st, 2008 13:13
games games, unknown unknown, Johann Hibschman, Greg Ewing


Problem:
-------------
def mark( a, b , **kw):
   print 'Mark' 
   passKeywords(kw) # THIS DOESN'T WORK!!! MAKE IT WORK!!!
def passKeywords( a,**kw )
   """ just do something  """
   print 'Gibson'
-------------
call it:
doSomething( 1,3,name='Mark',Last='Gibson')
produces:
Mark
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 3, in mark
TypeError: too many arguments; expected 0, got 1
-----------------
What I want to know is how do I pass kw from mark() to passKeywords()?
Solution:
apply(passKeywords, (), kw)
Or, in Python 2.0,
   passKeywords(**kw)
http://www.f01h.com/chat/sa.html
http://www.f01h.com/chat/ue.html
http://www.f01h.com/chat/ku.html
http://www.f01h.com/chat/bh.html
http://www.f01h.com/chat/qt.html
http://www.f01h.com/chat/om.html
http://www.f01h.com/chat/er.html
http://www.f01h.com/chat/ya.html
http://www.f01h.com/chat/eg.html
http://www.f01h.com/chat/tu.html
http://www.f01h.com/chat/je.html
http://www.f01h.com/chat/mo.html
http://www.f01h.com/chat/ly.html
http://www.f01h.com/chat/jo.html
http://www.f01h.com/chat/pl.html
http://www.f01h.com/chat/so.html
http://www.f01h.com/chat/mu.html
http://www.f01h.com/chat/tr.html
http://www.f01h.com/chat/
http://www.f01h.com/chat1/ry.html
http://www.f01h.com/chat1/sh.html
http://www.f01h.com/chat1/ko.html
http://www.f01h.com/chat1/dm.html
http://www.f01h.com/chat1/eh.html
http://www.f01h.com/chat1/qt.html
http://www.f01h.com/chat1/jn.html
http://www.f01h.com/chat1/ja.html
http://www.f01h.com/chat1/ab.html
http://www.f01h.com/chat1/3s.html
http://www.f01h.com/chat1/nj.html
http://www.f01h.com/chat1/dh.html
http://www.f01h.com/chat1/ba.html
http://www.f01h.com/chat1/qr.html
http://www.f01h.com/chat1/jd.html
http://www.f01h.com/chat1/mk.html
http://www.f01h.com/chat1/md.html
http://www.f01h.com/chat1/yn.html
http://www.f01h.com/chat1/shm.html
http://www.f01h.com/chat1/jo.html
http://www.f01h.com/chat1/3r.html
http://www.f01h.com/chat1/sk.html
http://www.f01h.com/chat1/qry.html
http://www.f01h.com/chat1/tb.html
http://www.f01h.com/chat1/wa.html
http://www.f01h.com/chat1/5m.html
http://www.f01h.com/chat1/jam.html
http://www.f01h.com/chat1/qs.html
http://www.f01h.com/chat1/kr.html
http://www.f01h.com/chat1
http://www.f01h.com/
http://www.f01h.com/vb/
http://www.r4r8.com/
http://www.r4r8.com/vb/
http://www.r4r8.com/hemo1
http://www.r4r8.com/vb/archive/index.php
http://www.r4r8.com/vb/archive/index.php/f-46.html
http://www.r4r8.com/vb/archive/index.php/f-89.html
http://www.r4r8.com/vb/archive/index.php/f-45.html
http://www.r4r8.com/vb/archive/index.php/f-4.html
http://www.r4r8.com/vb/archive/index.php/f-36.html
http://www.r4r8.com/vb/archive/index.php/f-2.html
http://www.r4r8.com/vb/archive/index.php/f-3.html
http://www.r4r8.com/vb/archive/index.php/f-65.html
http://www.r4r8.com/vb/archive/index.php/f-5.html
http://www.r4r8.com/vb/archive/index.php/f-56.html
http://www.r4r8.com/vb/archive/index.php/f-7.html
http://www.r4r8.com/vb/archive/index.php/f-8.html
http://www.r4r8.com/vb/archive/index.php/f-9.html
http://www.r4r8.com/vb/archive/index.php/f-11.html
http://www.r4r8.com/vb/archive/index.php/f-14.html
http://www.r4r8.com/vb/archive/index.php/f-63.html
http://www.r4r8.com/vb/archive/index.php/f-107.html
http://www.r4r8.com/vb/archive/index.php/f-13.html
http://www.r4r8.com/vb/archive/index.php/f-105.html
http://www.r4r8.com/vb/archive/index.php/f-16.html
http://www.r4r8.com/vb/archive/index.php/f-20.html
http://www.r4r8.com/vb/archive/index.php/f-21.html
http://www.r4r8.com/vb/archive/index.php/f-35.html
http://www.r4r8.com/vb/archive/index.php/f-81.html
http://www.r4r8.com/vb/archive/index.php/f-106.html
http://www.r4r8.com/vb/archive/index.php/f-27.html
http://www.r4r8.com/vb/archive/index.php/f-28.html
http://www.r4r8.com/vb/archive/index.php/f-30.html
http://www.r4r8.com/vb/archive/index.php/f-48.html
http://www.r4r8.com/vb/archive/index.php/f-112.html
http://www.r4r8.com/vb/archive/index.php/f-111.html
http://www.r4r8.com/vb/archive/index.php/f-77.html