class CombinedOpenForReading(object):

    def __init__(self, file_names):
        self._to_do = file_names[:]
self._fp = None

def __enter__(self):
    return self

def __exit__(self, exception_type, exception_value, exception_traceback):
    if self._fp:
        self._fp.close()

def read(self, size=None):
    res = ''
while True:
    if self._fp is None:
        if not self._to_do:
            return res
else:
    self._fp = open(self._to_do.pop(0))
if size is None:
    data = self._fp.read()
else:
    data = self._fp.read(size)
if size is None or not data:
    self._fp.close()
self._fp = None
res += data
if size is None:
    continue
size -= len(data)
if size == 0:
    break
return res
PyYaml combining two yaml files