有人有好的 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]];