def writeConfig(data, fileName, indent=2, encoding="utf-8"):
    """
    Writes the given data structure to the given file name. Based on the given extension
    a different file format is choosen. Currently use either .yaml or .json.
    """

    fileHandle = open(fileName, mode="w", encoding=encoding)

    fileExt = os.path.splitext(fileName)[1]
    if fileExt == ".json":
        json.dump(data, fileHandle, indent=indent, ensure_ascii=False)
        fileHandle.close()

    elif fileExt == ".yaml":
        yaml.dump(data, fileHandle, default_flow_style=False, indent=indent, allow_unicode=True)
        fileHandle.close()

    else:
        fileHandle.close()
        raise UserError("Unsupported config type: %s" % fileExt)
dataset/ETHPy150Open zynga/jasy/jasy/core/Config.py/writeConfig/original