title: Fast way to initialize class variables in Python
body: <p>I would like to initialize an instance and let both args and kwargs become class variables.</p>
  <pre class="lang-py prettyprint-override"><code>class Example():
      def __init__(
          self,
          a: str,
          b: bool,
          c: int,
          d=&quot;str&quot;,
          e=True,
          f=123,
      ):
          class_member = dict(locals())
          del class_member[&quot;self&quot;]
          self.set_property(class_member)
  
      @classmethod
      def set_property(cls, kwargs):
          for key, value in kwargs.items():
              setattr(cls, key, value)
  
  a = Example(&quot;test&quot;, True, 1, d=&quot;test&quot;, e=False, f=456)
  print(Example.d)  # test
  </code></pre>
  <p>I have searched a lot and get the above result.</p>
  <p>Is there any other cleaner way to deal with that? Thanks!</p>
  <p>--Edit--</p>
  <p>Thanks for all answers.
  My simplified version:</p>
  <pre class="lang-py prettyprint-override"><code>class Example():
      def __init__(
          self,
          a: str,
          b: bool,
          c: int,
          d=&quot;str&quot;,
          e=True,
          f=123,
      ):
          class_member = dict(locals())
          del class_member[&quot;self&quot;]
          for key, value in class_member.items():
              setattr(Example, key, value)
  
  a = Example(&quot;test&quot;, True, 1, d=&quot;test&quot;, e=False, f=456)
  print(Example.d)  # test
  </code></pre>
  <p>I had thought about using <code>**kwarg</code> previously, but I still need to assign default value for kwargs. So this is my final solution.</p>