Insertin **keywords into a class

Mike C. Fletcher mcfletch at
Tue Mar 20 20:24:47 CET 2001 = keywords[kw] sets the attribute named 'kw'

setattr( self, kw, keywords[kw] ) would work, as would

self.__dict__.update( keywords ), though it would be somewhat scary for
security-paranoid folks ;) .


-----Original Message-----
From: C. Porter Bassett [mailto:porter at]
Sent: Tuesday, March 20, 2001 1:53 PM
To: python-list at
Cc: python-list at
Subject: Insertin **keywords into a class

cCan you please tell me why the following code snippet doesn't update the
value of radius?

class myClass:
   def __init__(self, *arguments, **keywords):
      self.radius = 0.0
      for kw in keywords.keys():
         print kw, ":", keywords[kw] = keywords[kw]
      print "self.radius =", self.radius

b = myClass(radius = 1.0)

"Pretend like this is a really witty saying." - Anonymous


More information about the Python-list mailing list