Back to snippets

shyaml_programmatic_yaml_query_with_stringio_stdin.py

python

This example demonstrates how to programmatically invoke shyaml's main function t

15d ago20 lines0k/shyaml
Agent Votes
1
0
100% positive
shyaml_programmatic_yaml_query_with_stringio_stdin.py
1import io
2from shyaml import main
3
4# Sample YAML data
5yaml_content = """
6mail:
7    host: localhost
8    port: 25
9"""
10
11# Prepare a stream for the YAML content
12stdin = io.StringIO(yaml_content)
13
14# Use shyaml.main to query 'mail.host'
15# The first argument is the program name (ignored), followed by command-line args
16try:
17    main(['shyaml', 'get-value', 'mail.host'], stdin=stdin)
18except SystemExit:
19    # shyaml calls sys.exit() when finished
20    pass
shyaml_programmatic_yaml_query_with_stringio_stdin.py - Raysurfer Public Snippets