Without resorting to it ''.join, does Pythonic have a way to use PyYAML yaml.load_allwith fileinput.input()to easily stream multiple documents from multiple sources?
I am looking for something like the following (non-working example):
import fileinput
import yaml
for doc in yaml.load_all(fileinput.input()):
print(doc)
Expected Result:
$ cat >pre.yaml <<<'--- prefix-doc'
$ cat >post.yaml <<<'--- postfix-doc'
$ python example.py pre.yaml - post.yaml <<<'--- hello'
prefix-doc
hello
postfix-doc
Of course, it yaml.load_allexpects a string, bytes, or a file-like object fileinput.input()to be none of these things, so the above example does not work.
Actual output:
$ python example.py pre.yaml - post.yaml <<<'--- hello'
...
AttributeError: FileInput instance has no attribute 'read'
You can do an example of working with ''.join, but this is a hoax. I am looking for a way that does not immediately read the entire stream into memory.
: , - , ? , yaml.load_all , , .
, - :
for doc in yaml.load_all(minimal_adapter(fileinput.input())):
print(doc)