有人有好的 JSL .ini 文件阅读器吗?我在想象
[Thing1]
x = 14
y = String
z = ...
[Thing2]
x=DifferentString
y=28
成为
[
"Thing1"=>
["x"=>14, //not sure if this should be a number or string
"y"=>"String",
"z"=>"..."],
"Thing2"=>
["x"=>"DifferentString",
"y"=>28]
]
自动化和脚本回复:有人有好的 JSL .ini 文件阅读器吗?酷利奥。是的。 我真的只是想做同样的事情来整合我的多种语言/框架的配置。
一个使用 XML,一个 YML,一个 TOML,然后我有 python 和 JSL。我个人喜欢 YML 的可读性和评论。
在我问了这个之后我意识到我不能真正使用 INI 因为我需要嵌套(尽管我可以有一些命名约定并在我这边处理它)
这仍然非常有用。谢谢大家。
回复:有人有好的 JSL .ini 文件阅读器吗?我经常在 Oracle 数据库中读写关联数组。这是 .ini 文件的类似方法:
/*
Function Name: char_to_aa
Description: Convert a character string to an associative array
*/
char_to_aa = Function({one_char_aa},
if (contains(one_char_aa, "Associative Array"),
one_aa = eval(parse(one_char_aa));
,
one_aa = parse(one_char_aa);
);
one_aa;
);
//---------------------------------------------------------------------
// Now try this out
aa = associative array();
aa["Thing1"] = {14, "String", "z-value"};
aa["Thing2"] = {"DifferentString", 28, "other-z-value"};
// Convert the associative array to a char
char_aa = char(aa);
// Save it to a file
save text file("$temp\myfile.ini", char_aa);
write(char_aa);
// Convert it back to an associative array
new_char_aa = load text file("$temp\myfile.ini");
new_aa = char_to_aa(new_char_aa);
print(new_aa);回复:有人有好的 JSL .ini 文件阅读器吗?100% 同意 XML 和 JSON 以及转储的关联数组不适合在记事本中编辑。 编写自己的编辑器并不总是有意义,因此 .INI 文件仍然有它们的位置。
回复:有人有好的 JSL .ini 文件阅读器吗?在简单的情况下,我更喜欢 ini/config 文件而不是 JSON,因为它们通常更容易直接从文件中读取和编辑(这是好事还是坏事),当我使用 LabVIEW 时,格式变得熟悉配置文件六.
目前正在考虑如何在我的几个脚本中处理相当简单的配置文件。 我将不得不尝试使用 .jsl 或 json/.ini 文件。
Names Default To Here(1);
read_ini_file = function({ini_str}, {Default Local},
aa_ini = Associative Array();
cur_key = "";
For Each({line}, Words(ini_str, "\!N"),
If(Ends With(line, "]") & Starts With(line, "["),
new_key = Word(1, line, "[]");
aa_ini[Word(1, line, "[]")] = Associative Array();
cur_key = new_key;
,
{key, value} = Words(line, "=");
//string conversion.. expect everything to be numbers and then try to convert
new_value = If(Is Missing(Num(value)),
Trim(value),
Num(value)
);
aa_ini[cur_key][Trim(key)] = new_value;
)
);
return(aa_ini);
);
aa_to_ini = function({aa_section}, {Default Local},
ini_str = "";
section = "\!N[^key_section^]\!N";
key_value = "^key^=^value^\!N";
For Each({{key_section, value_section}}, aa_section,
ini_str ||= Eval Insert(section);
For Each({{key, value}}, value_section,
ini_str ||= Eval Insert(key_value);
);
);
return(Trim Whitespace(ini_str,left));
);
config_file = "[Thing1]
x=14
y=String
z=...
[Thing2]
x=DifferentString with space
y=28
";
aa_test = read_ini_file(config_file);
back_to_ini = aa_to_ini(aa_test);
show(aa_test,back_to_ini,config_file);
//back_to_ini == config_file;
//aa_test == read_ini_file(back_to_ini)
//Save Text File("$TEMP/DeleteMe.txt", back_to_ini);
//Open("$TEMP");
//config_file = Load Text File("$TEMP/DeleteMe.txt");
//aa_test == read_ini_file(back_to_ini);
//aa_test["Thing1"]["x"]
回复:有人有好的 JSL .ini 文件阅读器吗?好的! 它确实需要修剪键和值。
config_file =
"[Thing1]
x = 14
y = String
z = ...
[Thing2]
x=DifferentString with space
y=28
";
aa_ini = Associative Array();
cur_key = "";
For Each( {line}, Words( config_file, "\!N" ),
If( Ends With( line, "]" ) & Starts With( line, "[" ),
new_key = Word( 1, line, "[]" );
aa_ini[Word( 1, line, "[]" )] = Associative Array();
cur_key = new_key;
,
{key, value} = Words( line, "=" );
//string conversion.. expect everything to be numbers and then try to convert
new_value = If( Is Missing( Num( value ) ),
Trim( value ),
Num( value )
);
aa_ini[cur_key][Trim( key )] = new_value;
)
);
Write( As JSON Expr( aa_ini ) );
将那些 .ini 文件移动到当前世纪!
{"Thing1":{"x":14,"y":"String","z":"..."},"Thing2":{"x":"DifferentString with space","y": 28}}
有时很难判断 JSON 是进步还是倒退。
回复:有人有好的 JSL .ini 文件阅读器吗?我想当我想在 python 和 JMP 中使用相同的配置文件时我做了类似的事情,但放弃了不记得为什么。 但我必须对 Minitab MAC 文件进行一些解析,同样的想法在这里可能也适用。
下面是修改后的脚本以适应这种类型的字符串。 可能需要添加 Trim Whitespace:
Names Default To Here(1);
config_file = "[Thing1]
x = 14
y = String
z = ...
[Thing2]
x=DifferentString
y=28
";
aa_ini = Associative Array();
cur_key = "";
For Each({line}, Words(config_file, "\!N"),
If(Ends With(line, "]") & Starts With(line, "["),
new_key = Word(1, line, "[]");
aa_ini[Word(1, line, "[]")] = Associative Array();
cur_key = new_key;
,
{key, value} = Words(line, "=");
//string conversion.. expect everything to be numbers and then try to convert
new_value = If(IsMissing(num(value)),
value,
num(value)
);
aa_ini[cur_key][key] = new_value;
);
);
show(aa_ini);<BR /><BR />aa_ini = ["Thing1" => ["x " => 14, "y " => " String", "z " => " ..."], "Thing2" => ["x" => "DifferentString", "y" => 28]];