code_junkie

Python's ConfigParser unique keys per section

Nov 12th, 2011
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. >>> from ConfigParser import ConfigParser
  2. >>> from StringIO import StringIO
  3. >>> fh = StringIO("""
  4. ... [Some Section]
  5. ... spam: eggs
  6. ... spam: ham
  7. ... """)
  8. >>> parser = ConfigParser()
  9. >>> parser.readfp(fh)
  10. >>> print parser.items('Some Section')
  11. [('spam', 'ham')]
  12.  
  13. [Ignored Paths]
  14. ignore-extension: .swp
  15. ignore-filename: tags
  16. ignore-directory: bin
  17.  
  18. [('spam', 'eggs'), ('spam', 'ham')]
  19.  
  20. parser.get('Some Section', 'spam')
  21.  
  22. [Some Section]
  23. spam: eggs, ham
  24.  
  25. spam_values = [v.strip() for v in parser.get('Some Section', 'spam').split(',')]
Add Comment
Please, Sign In to add comment