title: Python: Read text file into dict and ignore comments
body: <p>I am trying to put the following text file into a dictionary but I would like any section starting with '#' or empty lines ignored. </p>
  
  <p>My text file looks something like this:</p>
  
  <pre><code># This is my header info followed by an empty line
  
  Apples          1                # I want to ignore this comment
  Oranges         3                # I want to ignore this comment
  
  #~*~*~*~*~*~*~*Another comment~*~*~*~*~*~*~*~*~*~*
  
  Bananas         5                # I want to ignore this comment too!
  </code></pre>
  
  <p>My desired output would be:</p>
  
  <pre><code>myVariables = {'Apples': 1, 'Oranges': 3, 'Bananas': 5}
  </code></pre>
  
  <p>My Python code reads as follows:</p>
  
  <pre><code>filename = "myFile.txt"
  myVariables = {}
  
  with open(filename) as f:
      for line in f:
          if line.startswith('#') or not line:
              next(f)
  
          key, val = line.split()
          myVariables[key] = val
          print "key: " + str(key) + " and value: " + str(val)
  </code></pre>
  
  <p>The error I get:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/Python27/test_1.py", line 11, in &lt;module&gt;
      key, val = line.split()
  ValueError: need more than 1 value to unpack
  </code></pre>
  
  <p>I understand the error but I do not understand what is wrong with the code. </p>
  
  <p>Thank you in advance!</p>