有人有好的 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 文件阅读器吗?当我想在 python 和 JMP 中使用相同的配置文件时,我想我做了这样的事情,但放弃了不记得为什么。 但我必须对 Minitab MAC 文件进行一些解析,同样的想法在这里可能会奏效。
下面是修改脚本以适应这种类型的字符串。 可能需要添加修剪空白:
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]];回复:有人有好的 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 文件阅读器吗?在简单的情况下,我更喜欢 ini/config 文件而不是 JSON,因为它们通常更容易直接从文件中读取和编辑(无论是好事还是坏事),而且当我使用 LabVIEW 时,格式变得熟悉了配置文件 VI .
目前正在考虑如何在我的几个脚本中处理相当简单的配置文件。 我将不得不只使用 .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 文件阅读器吗?100% 同意 XML 和 JSON 以及转储的关联数组不打算在记事本中编辑。 编写自己的编辑器并不总是有意义的,因此 .INI 文件仍然占有一席之地。