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":"공백이 있는 다른 문자열","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 파일이 여전히 제자리에 있습니다.