Insertin **keywords into a class

Mike C. Fletcher mcfletch at home.com
Tue Mar 20 14:24:47 EST 2001


self.kw = 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 ;) .

Enjoy,
Mike

-----Original Message-----
From: C. Porter Bassett [mailto:porter at et.byu.edu]
Sent: Tuesday, March 20, 2001 1:53 PM
To: python-list at python.org
Cc: python-list at python.org
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]
         self.kw = keywords[kw]
      print "self.radius =", self.radius


b = myClass(radius = 1.0)


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


--
http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list