title: Python: How to create a dictionary from properties file while omitting comments
body: <p>I've searched for the answer to this here for awhile and haven't found it, so hope this isn't a dupe.  </p>
  
  <p>I have a properties file that mostly contains key=value pairs, but also contains #comments.  I need to put it in a dictionary so I can grab values at will.  In a file without #comments, the following works perfectly.</p>
  
  <pre><code>myprops = dict(line.strip().split('=') for line in open('/Path/filename.properties'))
  print myprops['key']
  </code></pre>
  
  <p>But not so when there are comments present.  If there's <code>#comment</code> present, dictionary says</p>
  
  <pre><code>"ValueError: dictionary update sequence element #x has length 1, 2 is required"
  </code></pre>
  
  <p>I've tried wrapping the dictionary creation in conditionals with</p>
  
  <pre><code>if not line.startswith('#'):
  </code></pre>
  
  <p>But I can't seem to get that to work.  Suggestions?  Thanks!</p>