geändert: README.md
geändert: config_parser.py
This commit is contained in:
@@ -1,3 +1,38 @@
|
|||||||
# config-parser
|
# config-parser
|
||||||
|
|
||||||
A library to parse configuration files.
|
A library to parse configuration files. Currently it supports only INI format, but support for other formats is planned.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
You can install the library using pip:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install config-parser --index-url https://jcloud-services.ddns.net/simple/
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
Here's a simple example of how to use the `config-parser` library to read an INI configuration file:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from config_parser import parse_ini
|
||||||
|
|
||||||
|
with open('config.conf', 'r') as file:
|
||||||
|
config_content = file.read()
|
||||||
|
|
||||||
|
parsed = parse_ini(config_content)
|
||||||
|
print(parsed)
|
||||||
|
```
|
||||||
|
|
||||||
|
If the configuration file content is:
|
||||||
|
```ini
|
||||||
|
[section1]
|
||||||
|
key1=value1
|
||||||
|
key2=value2
|
||||||
|
|
||||||
|
[section2]
|
||||||
|
hello=world
|
||||||
|
|
||||||
|
[section3]
|
||||||
|
key=value
|
||||||
|
```
|
||||||
|
|
||||||
|
the result will be `{'section1': {'key1': 'value1', 'key2': 'value2'}, 'section2': {'hello': 'world'}, 'section3': {'key': 'value'}}`
|
||||||
+1
-1
@@ -31,7 +31,7 @@ def compress_conf(conf):
|
|||||||
conf = conf.replace('\n\n', '\n')
|
conf = conf.replace('\n\n', '\n')
|
||||||
return conf.strip()
|
return conf.strip()
|
||||||
|
|
||||||
def parse_conf(conf):
|
def parse_ini(conf):
|
||||||
conf = compress_conf(conf)
|
conf = compress_conf(conf)
|
||||||
result = {}
|
result = {}
|
||||||
current_group = {}
|
current_group = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user