title: How to set class variable through __init__ in Python?
body: <p>I am trying to change setting from command line while starting a scrapy crawler (Python 3.7). Therefore I am adding a <strong>init</strong> method, but I could not figure out how to change the class varible &quot;delay&quot; from within the <strong>init</strong> method.</p>
  <p>Example minimal:</p>
  <pre><code>class testSpider(CrawlSpider):
  
      custom_settings = {
          'DOWNLOAD_DELAY': 10,  # default value
      }
  
      &quot;&quot;&quot; get arguments passed over CLI
          scrapyd usage: -d arg1=val1
          scrapy  usage: -a arg1=val1
      &quot;&quot;&quot;
      def __init__(self, *args, **kwargs):
          super(testSpider, self).__init__(*args, **kwargs)
  
          self.delay = kwargs.get('delay')
  
          if self.delay:
              testSpider.custom_settings['DOWNLOAD_DELAY'] = self.delay
              print('init:', testSpider.custom_settings['DOWNLOAD_DELAY'])
  
      print(custom_settings['DOWNLOAD_DELAY'])
  </code></pre>
  <p>This will not change the setting unfortunatelly:</p>
  <pre><code>scrapy crawl test -a delay=5
  10
  init: 5
  </code></pre>
  <p>How can the class variable be changed?</p>