¿Alguien tiene un buen lector de archivos JSL .ini?Me lo estoy imaginando
[Thing1]
x = 14
y = String
z = ...
[Thing2]
x=DifferentString
y=28
devenir
[
"Thing1"=>
["x"=>14, //not sure if this should be a number or string
"y"=>"String",
"z"=>"..."],
"Thing2"=>
["x"=>"DifferentString",
"y"=>28]
]
Automatización y scriptingRe: ¿Alguien tiene un buen lector de archivos JSL .ini?Creo que hice algo como esto cuando quería usar el mismo archivo de configuración en Python y JMP, pero me di por vencido, no recuerdo por qué. Pero tuve que analizar un poco los archivos MAC de Minitab y la misma idea podría funcionar aquí.
A continuación se muestra un script modificado para adaptarse a este tipo de cadenas. Puede requerir agregar 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]];Re: ¿Alguien tiene un buen lector de archivos JSL .ini?¡bonito! Necesita recortar por clave y valor.
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 ) );
¡Mueva esos archivos .ini al siglo actual!
{"Thing1": {"x": 14, "y": "String", "z": "..."}, "Thing2": {"x": "DifferentString con espacio", "y": 28}}
A veces es difícil saber si JSON es un paso adelante o atrás.