gpt4 book ai didi

TCL 将数据写入 YAML 文件

转载 作者:行者123 更新时间:2023-12-04 12:51:11 40 4
gpt4 key购买 nike

我有一个正在捕获一些数据的 tcl 脚本。我想将此数据写入 YAML 文件。有没有我可以阅读的关于如何在 TCL 中执行此操作的示例或位置?

最佳答案

yaml package在 Tcllib 中做到了。

如果您的数据是一个简单的单级字典,您可以这样做:

package require yaml

set yamlText [yaml::dict2yaml $yourDictionary]

例如:

% set d {foo 123 bar "this is a piece of text"}
foo 123 bar "this is a piece of text"
% yaml::dict2yaml $d
---
foo: 123
bar: this is a piece of text

%

这个的主要问题是它假设每个键中的所有内容都是一个字符串(尽管数字通常足够短,结果也不错)。

因此,如果您的数据更复杂,您需要使用 huddle package 构建它的拥挤描述第一的。这嵌入了生成复杂结构所需的额外类型信息。

package require huddle
package require yaml

set inner [huddle create boo "this is some text" grill "this is some other text"]
set outer [huddle create foo 123 bar $inner]
yaml::huddle2yaml $outer

关于TCL 将数据写入 YAML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38033668/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com