| 1 |
--- |
| 2 |
title: Why does StrictYAML only parse from strings and not files? |
| 3 |
--- |
| 4 |
|
| 5 |
While other parsers will take strings, file handles and file names, |
| 6 |
StrictYAML will only parse YAML strings. |
| 7 |
|
| 8 |
This is done deliberately to reduce the module's remit, with the |
| 9 |
intention of reducing both the potential bug surface and the number |
| 10 |
of exceptions that StrictYAML has to deal with - things like |
| 11 |
nonexistent files, file system errors, bad reads, unknown file |
| 12 |
extensions, etc. become the problem of some other module - ideally |
| 13 |
one more focused on handling those kinds of issues. |
| 14 |
|
| 15 |
If you want a quick and easy one liner way to get text from a file, |
| 16 |
I recommend that you pip install path.py and and use .text() on the |
| 17 |
Path object: |
| 18 |
|
| 19 |
```python |
| 20 |
>>> from path import Path |
| 21 |
>>> from strictyaml import load |
| 22 |
>>> parsed_data = load(Path("myfile.yaml").text()).data |
| 23 |
>>> print(parsed_data) |
| 24 |
[ parsed yaml ] |
| 25 |
``` |
| 26 |
|
| 27 |
|
| 28 |
## Counterarguments |
| 29 |
|
| 30 |
- <https://github.com/crdoconnor/strictyaml/issues/5> |