aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-07-30 00:20:20 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2020-07-30 00:20:20 -0500
commit633facbbd9db0be86be88ffc95996038a68db4fa (patch)
treeca99ed22e179db96b6cbed7ca95866039ce44518
parentUpdate code to be inside code block (diff)
downloadconfig-file-633facbbd9db0be86be88ffc95996038a68db4fa.zip
Add `has`, `delete`, and `set` usage
-rw-r--r--README.md52
1 files changed, 51 insertions, 1 deletions
diff --git a/README.md b/README.md
index 04d4090..f7067e4 100644
--- a/README.md
+++ b/README.md
@@ -165,13 +165,63 @@ config.set('section.num_key', 6)
```
The method does not return anything, since there is nothing
-useful to return.
+useful to return. If someone goes wrong where it is unable to set
+the value, an exception will be raised instead.
+
+With `set()`, we can also create and set keys that don't exist yet.
+
+```python
+config.set('new_section.new_key', 'New key value!')
+```
+
+Would then result in the following section being added to our original file:
+
+```ini
+[new_section]
+new_key = New key value!
+```
+
+The exact behavior of how these new keys or sections are added are a bit
+dependent on the file format we're using. See the [full documentation](#Documentation) for
+more information there.
### Using `delete()`
+`delete()` allows us to delete entire sections or specific keys.
+
+```python
+config.delete('section')
+```
+
+Would result in the entire section being removed from our configuration file.
+However, we can also just delete a single key.
+
+```python
+config.delete('section.num_key')
+```
### Using `has()`
+`has()` allows us to check whether a given key exists in our file. There
+are two ways to use `has()`.
+
+The first is using the dot syntax.
+
+```python
+config.has('section.str_key')
+>>> True
+config.has('does_not_exist')
+>>> False
+```
+
+This will check if our specific key or section exists. However, we can
+also just check in general if a given key exists anywhere in our file
+with the `wild` keyword argument.
+
+```python
+config.has('str_key', wild=True)
+>>> True
+```
### Using `stringify()`