Skip to content

Instantly share code, notes, and snippets.

@borntyping
Last active August 20, 2019 13:34
Show Gist options
  • Save borntyping/27e4529b8ac17c1ad9a7a72369525365 to your computer and use it in GitHub Desktop.
Save borntyping/27e4529b8ac17c1ad9a7a72369525365 to your computer and use it in GitHub Desktop.
import yaml
import pathlib
print(yaml.load(pathlib.Path("apply.yaml").read_text()))
$ pipenv run python apply.py
example.py:4: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
print(yaml.load(pathlib.Path("example.yaml").read_text()))
Traceback (most recent call last):
File "example.py", line 4, in <module>
print(yaml.load(pathlib.Path("example.yaml").read_text()))
File "/home/sam/.local/share/virtualenvs/yaml-M4-appFz/lib/python3.7/site-packages/yaml/__init__.py", line 114, in load
return loader.get_single_data()
File "/home/sam/.local/share/virtualenvs/yaml-M4-appFz/lib/python3.7/site-packages/yaml/constructor.py", line 43, in get_single_data
return self.construct_document(node)
File "/home/sam/.local/share/virtualenvs/yaml-M4-appFz/lib/python3.7/site-packages/yaml/constructor.py", line 47, in construct_document
data = self.construct_object(node)
File "/home/sam/.local/share/virtualenvs/yaml-M4-appFz/lib/python3.7/site-packages/yaml/constructor.py", line 94, in construct_object
data = constructor(self, tag_suffix, node)
File "/home/sam/.local/share/virtualenvs/yaml-M4-appFz/lib/python3.7/site-packages/yaml/constructor.py", line 624, in construct_python_object_apply
instance = self.make_python_instance(suffix, node, args, kwds, newobj)
File "/home/sam/.local/share/virtualenvs/yaml-M4-appFz/lib/python3.7/site-packages/yaml/constructor.py", line 570, in make_python_instance
node.start_mark)
yaml.constructor.ConstructorError: while constructing a Python instance
expected a class, but found <class 'builtin_function_or_method'>
in "<unicode string>", line 1, column 1:
!!python/object/apply:os.system
^
!!python/object/apply:os.system
args: ['ls /']
import yaml
import pathlib
print(yaml.load(pathlib.Path("load.yaml").read_text()))
$ pipenv run python load.py
example.py:4: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
print(yaml.load(pathlib.Path("load.yaml").read_text()))
{'args': ['ls /']}
args: ['ls /']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment