diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2020-08-07 08:58:26 -0500 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2020-08-07 08:58:26 -0500 |
| commit | c7a873ba71d1103b66c1cdf93451cb03ddf19832 (patch) | |
| tree | f7a43843b198b730f057a49114c057b877ef1364 | |
| parent | Remove all custom exceptions except ParsingError (diff) | |
| download | config-file-c7a873ba71d1103b66c1cdf93451cb03ddf19832.zip | |
Add information on indexing into ConfigFile
| -rw-r--r-- | README.md | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -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 |