Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pytest-dev/iniconfig
https://github.com/pytest-dev/iniconfig
Last synced: 13 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/pytest-dev/iniconfig
- Owner: pytest-dev
- License: mit
- Created: 2016-08-18T16:20:15.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2024-09-03T11:06:08.000Z (2 months ago)
- Last Synced: 2024-10-29T15:52:10.624Z (15 days ago)
- Language: Python
- Size: 99.6 KB
- Stars: 56
- Watchers: 6
- Forks: 31
- Open Issues: 4
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG
- License: LICENSE
Awesome Lists containing this project
README
iniconfig: brain-dead simple parsing of ini files
=======================================================iniconfig is a small and simple INI-file parser module
having a unique set of features:* maintains order of sections and entries
* supports multi-line values with or without line-continuations
* supports "#" comments everywhere
* raises errors with proper line-numbers
* no bells and whistles like automatic substitutions
* iniconfig raises an Error if two sections have the same name.If you encounter issues or have feature wishes please report them to:
https://github.com/RonnyPfannschmidt/iniconfig/issues
Basic Example
===================================If you have an ini file like this:
.. code-block:: ini
# content of example.ini
[section1] # comment
name1=value1 # comment
name1b=value1,value2 # comment[section2]
name2=
line1
line2then you can do:
.. code-block:: pycon
>>> import iniconfig
>>> ini = iniconfig.IniConfig("example.ini")
>>> ini['section1']['name1'] # raises KeyError if not exists
'value1'
>>> ini.get('section1', 'name1b', [], lambda x: x.split(","))
['value1', 'value2']
>>> ini.get('section1', 'notexist', [], lambda x: x.split(","))
[]
>>> [x.name for x in list(ini)]
['section1', 'section2']
>>> list(list(ini)[0].items())
[('name1', 'value1'), ('name1b', 'value1,value2')]
>>> 'section1' in ini
True
>>> 'inexistendsection' in ini
False