A wrapper for the open() builtin which makes parent directories if needed.

def mkopen(p, *args, **kwargs):
    """
    A wrapper for the open() builtin which makes parent directories if needed.
    """
    dir = os.path.dirname(p)
    mkdir(dir)
    return open(p, *args, **kwargs)