Forwarding keyword arguments from one function to another

Ravi ra.ravi.rav at gmail.com
Sun Feb 22 21:09:26 CET 2009


I am sorry about the typo mistake, well the code snippets are as:

# Non Working:

class X(object):
  def f(self, **kwds):
  print kwds
  try:
    print kwds['i'] * 2
  except KeyError:
    print "unknown keyword argument"
    self.g("string", kwds)

  def g(self, s, **kwds):
    print s
    print kwds

if __name__ == "__main__":
x = X()
x.f(k = 2, j = 10)


# Working One

class X(object):
  def f(self, **kwds):
    print kwds
    try:
      print kwds['i'] * 2
    except KeyError:
     print "unknown keyword argument"
   self.g("string", **kwds)

def g(self, s, **kwds):
  print s
  print kwds

if __name__ == "__main__":
x = X()
x.f(k = 2, j = 10)



More information about the Python-list mailing list