aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-08-07 08:58:26 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2020-08-07 08:58:26 -0500
commitc7a873ba71d1103b66c1cdf93451cb03ddf19832 (patch)
treef7a43843b198b730f057a49114c057b877ef1364
parentRemove all custom exceptions except ParsingError (diff)
downloadconfig-file-c7a873ba71d1103b66c1cdf93451cb03ddf19832.zip
Add information on indexing into ConfigFile
-rw-r--r--README.md28
1 files changed, 28 insertions, 0 deletions
diff --git a/README.md b/README.md
index 96a27af..c1d4e9a 100644
--- a/README.md
+++ b/README.md
@@ -96,6 +96,14 @@ config.get('section')
>>> {'num_key': '5', 'str_key': 'blah', 'bool_key': 'true', 'list_key': '[1, 2]'}
```
+Furthermore, you can also index into the `ConfigFile` object
+to retrieve keys if that is preferred.
+
+```python
+config['section']['num_key']
+>>> '5'
+```
+
#### Coercing the return types
However, some of these keys are obviously not strings natively.
@@ -181,6 +189,20 @@ dependent on the file format we're using, since every format is a little
different in it's structure and in what it supports. See the
[full documentation](#Documentation) for more information there.
+Lastly, we can set values using an array notation as well. The underlying
+content is all manipulated as a dictionary for every file type. If we wanted
+to create a new section, we'd simply set it to be an empty dictionary.
+
+```python
+config['new_section'] = {}
+```
+
+Which would result to be an empty section:
+
+```ini
+[new_section]
+```
+
### Using `delete()`
`delete()` allows us to delete entire sections or specific keys.
@@ -196,6 +218,12 @@ However, we can also just delete a single key.
config.delete('section.num_key')
```
+We can also use the array notation here as well.
+
+```python
+del config['section']['num_key']
+```
+
### Using `has()`
`has()` allows us to check whether a given key exists in our file. There