#!/usr/bin/python3 import sys import yaml def print_help(): print("./config.py ", file=sys.stderr) def readvalue(config_file, key): try: with open(config_file, 'r', encoding="utf-8") as f: data = yaml.load(f, Loader=yaml.Loader) value = data[key] print(value) except yaml.YAMLError as e: print('YAMLError: %s' % e, file=sys.stderr) except KeyError as e: print('KeyError: %s' % e, file=sys.stderr) if __name__ == "__main__": args = sys.argv[1:] if '--help' in args: print_help() sys.exit(1) if len(args) == 2: input_file = args[0] input_key = args[1] readvalue(input_file, input_key) elif len(args) < 2: print("Error: missing required arguments.", file=sys.stderr) print_help() sys.exit(1) else: print("Error: too many arguments.", file=sys.stderr) print_help() sys.exit(1)