title: load parameters from a file in Python
body: <p>I am writing a Python class to model a process and I want to initialized the parameters from a file, say <code>'input.dat'</code>. The format of the input file looks like this.</p>
  
  <p><code>'input.dat'</code> file:</p>
  
  <pre class="lang-none prettyprint-override"><code>Z0: 0 0
  k: 0.1
  g: 1
  Delta: 20
  t_end: 300
  </code></pre>
  
  <p>The code I wrote is the following. It works but appears redundant and inflexible. Is there a better way to do the job? Such as a loop to do readline() and then match the keyword?</p>
  
  <pre><code>def load(self,filename="input.dat"):
      FILE = open(filename)
      s = FILE.readline().split()
      if len(s) is 3:
          self.z0 = [float(s[1]),float(s[2])] # initial state
      s = FILE.readline().split()
      if len(s) is 2:
          self.k = float(s[1])    # kappa
      s = FILE.readline().split()
      if len(s) is 2:
          self.g = float(s[1])
      s = FILE.readline().split()
      if len(s) is 2:
          self.D = float(s[1])    #  Delta
      s = FILE.readline().split()
      if len(s) is 2:
          self.T = float(s[1])    # end time
  </code></pre>