優れた 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]
]
自動化とスクリプトRe:誰もが優れた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]];Re:誰もが優れた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が一歩前進か後退かを見分けるのが難しい場合があります。
Re:誰もが優れたJSL .iniファイルリーダーを持っていますか?単純なケースでは、JSONよりもini / configファイルの方が好きです。これは、通常、ファイルから直接読み取って編集する方が簡単であり(これは良いことでも悪いことでも)、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"]
Re:誰もが優れたJSL .iniファイルリーダーを持っていますか?XMLやJSONよりも100%同意しており、ダンプされた連想配列はメモ帳で編集するためのものではありません。 また、独自のエディタを作成することは必ずしも意味がないため、.INIファイルは引き続き使用できます。