README.rst 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. iniconfig: brain-dead simple parsing of ini files
  2. =======================================================
  3. iniconfig is a small and simple INI-file parser module
  4. having a unique set of features:
  5. * maintains order of sections and entries
  6. * supports multi-line values with or without line-continuations
  7. * supports "#" comments everywhere
  8. * raises errors with proper line-numbers
  9. * no bells and whistles like automatic substitutions
  10. * iniconfig raises an Error if two sections have the same name.
  11. If you encounter issues or have feature wishes please report them to:
  12. https://github.com/RonnyPfannschmidt/iniconfig/issues
  13. Basic Example
  14. ===================================
  15. If you have an ini file like this:
  16. .. code-block:: ini
  17. # content of example.ini
  18. [section1] # comment
  19. name1=value1 # comment
  20. name1b=value1,value2 # comment
  21. [section2]
  22. name2=
  23. line1
  24. line2
  25. then you can do:
  26. .. code-block:: pycon
  27. >>> import iniconfig
  28. >>> ini = iniconfig.IniConfig("example.ini")
  29. >>> ini['section1']['name1'] # raises KeyError if not exists
  30. 'value1'
  31. >>> ini.get('section1', 'name1b', [], lambda x: x.split(","))
  32. ['value1', 'value2']
  33. >>> ini.get('section1', 'notexist', [], lambda x: x.split(","))
  34. []
  35. >>> [x.name for x in list(ini)]
  36. ['section1', 'section2']
  37. >>> list(list(ini)[0].items())
  38. [('name1', 'value1'), ('name1b', 'value1,value2')]
  39. >>> 'section1' in ini
  40. True
  41. >>> 'inexistendsection' in ini
  42. False