title: Best practice when defining instance variables
body: <p>I'm fairly new to Python and have a question regarding the following class:</p>
  
  <pre><code>class Configuration:
      def __init__(self):
          parser = SafeConfigParser()
          try:
              if parser.read(CONFIG_FILE) is None:
                  raise IOError('Cannot open configuration file')
          except IOError, error:
              sys.exit(error)
          else:
              self.__parser = parser
              self.fileName = CONFIG_FILE
  
      def get_section(self):
          p = self.__parser
          result = []
          for s in p.sections():
              result.append('{0}'.format(s))
          return result
  
      def get_info(self, config_section):
          p = self.__parser
          self.section = config_section
          self.url = p.get(config_section, 'url')
          self.imgexpr = p.get(config_section, 'imgexpr')
          self.imgattr1 = p.get(config_section, 'imgattr1')
          self.imgattr2 = p.get(config_section, 'imgattr2')
          self.destination = p.get(config_section, 'destination')
          self.createzip = p.get(config_section, 'createzip')
          self.pagesnumber = p.get(config_section, 'pagesnumber')
  </code></pre>
  
  <p>Is it OK to add more instance variables in another function, <code>get_info</code> in this example, or is it best practice to define all instance variables in the constructor? Couldn't it lead to spaghetti code if I define new instance variables all over the place?</p>
  
  <p>EDIT: I'm using this code with a simple image scraper. Via <code>get_section</code> I return all sections in the config file, and then iterate through them to visit each site that I'm scraping images from. For each iteration I make a call to <code>get_section</code> to get the configuration settings for each section in the config file.
  If anyone can come up with another approach it'll be fine! Thanks!</p>