dolphindb - 如何读取 .cfg 文件中的内容并将其解析成字典?
问题描述
如何读取 .cfg 文件中的内容并将其解析成字典?
配置如下:
uid = reader
pwd = xxxxxx
driver =MySQL
port = 43306
db = xxxxxx
ip = 192.168.xxx.xxx
解决方案
自定义函数,读取 CFG 文件并将其转换为字典。
def getMysqlConnDict() {
f = file("/data/software/dolphin/server/mysqlconn.cfg")
arr = f.readLines()
connDict = dict(STRING, ANY)
for(i in 0:arr.size()) {
connDict[trim(split(arr[i], "=")[0])] = trim(split(arr[i], "=")[1])
}
return connDict
}
connDict = getMysqlConnDict()
推荐阅读
- jquery - JQuery 函数,应该只在某个类上触发,即使从标签中删除类也会继续触发
- css - 在不知道组件数量的情况下粘贴位置的纯 css 堆叠
- python - 需要列表中最后 x 个元素的随机值
- php - 有没有办法将 JsonSerializable 对象作为数组参数传递?
- tensorflow - 模块“tensorflow”在 TF2.1.0 中没有属性“contrib”
- java - 休眠连接获取
- python - Plotly:如何在条形图中添加趋势线?
- java - Java 11 编译错误:包 xxx 存在于另一个模块中
- java - 创建列表并分配值
- python - Python:使用结构库的部署不起作用 - 错误:未知命令“deploy:3.6.3”