def other_open(*args, **kwargs): fh = StringIO(''' k1: v1 k2: - v21 ''') fh.__exit__ = lambda x,y,z: None fh.__enter__ = lambda : fh return fh