SHARE
TWEET

Why you shouldn't mess with __dict__

a guest Jul 14th, 2011 52 Never
  1. class A(object):
  2.     def __init__(self, **kwargs):
  3.         self._b ='Default'
  4.         self.__dict__.update(kwargs)
  5.  
  6.     @property
  7.     def b(self):
  8.         return self._b
  9.  
  10.     @b.setter
  11.     def b(self, value):
  12.         self._b = value
  13.  
  14. a = A(b=1, c=2)
  15. print a.b, a.c
RAW Paste Data
Top