def open_mkdir(filename, mode='wb', *args, **kwargs):
    if mode not in ('w', 'wb'):
        raise ValueError('utils.file.open expects to write.')
    (dirname, basename) = os.path.split(filename)
    os.makedirs(dirname)
    return open(filename, mode, *args, **kwargs)
filename -> file object.
dataset/ETHPy150Open ProgVal/Limnoria/src/utils/file.py/open_mkdir