░█▀▀░█▀█░█▀█░▀█▀░█▀█░█▀▄░▄▀▄░█▀█░░░░█▀▀░█▀█░█▀▄░█▄█
░█░█░█░█░█▀█░░█░░█▀▀░█▀▄░█/█░█░█░░░░█▀▀░█▀█░█▀▄░█░█
░▀▀▀░▀▀▀░▀░▀░░▀░░▀░░░▀░▀░░▀░░▀░▀░▀░░▀░░░▀░▀░▀░▀░▀░▀
  .,-:::::/     ...      :::.:::::::::::::::::::::.:::::::..       :::.    :::..-:::::':::.   :::::::..  .        :   
,;;-'````'   .;;;;;;;.   ;;`;;;;;;;;;''''`;;;```.;;;;;;``;;;;   ,;;`;;;;,  `;;;;;;'''' ;;`;;  ;;;;``;;;; ;;,.    ;;;  
[[[   [[[[[[,[[     \[[,,[[ '[[,  [[      `]]nnn]]' [[[,/[[[' ,['  [n[[[[[. '[[[[[,,==,[[ '[[, [[[,/[[[' [[[[, ,[[[[, 
"$$c.    "$$$$$,     $$c$$$cc$$$c $$       $$$""    $$$$$$c   $$    $$$$ "Y$c$$`$$$"`c$$$cc$$$c$$$$$$c   $$$$$$$$"$$$ 
 `Y8bo,,,o88"888,_ _,88P888   888,88,      888o     888b "88boY8,  ,8888    Y8d8888   888   888888b "88bo888 Y88" 888o
   `'YMUP"YMM "YMMMMMP" YMM   ""` MMM      YMMMb    MMMM   "W" "YmmP MMM     YYM"MM,  YMM   ""`MMMM   "W"MMM  M'  "MMM
GoatPr0n.farm

Easy pyyaml '!include' Tag


Easy pyymal file inclusion

YAML does not support file inclusion. If this feature is needed, it is necessary to write your own constructor to support a new tag like !include.

Example YAML files

foo.yaml:

hello: !include bar.yaml

bar.yaml:

'world'

resulting yaml:

hello: 'world'

Example code

import yaml


def include_constructor(loader, node):
    filename = node.value
    include = yaml.load(open(filename, 'r'), Loader=yaml.SafeLoader)
    return include


Loader = yaml.CLoader
Loader.add_constructor(u'!include', include_constructor)


yaml_data = yaml.load(open('foo.yaml', 'r'), Loader=yaml.CLoader)

KTHXBYE.