Come includere funzioni specifiche invece dell'intero scriptCiao,
C'è un modo per importare solo funzioni specifiche da un file JSL?
Ad esempio in python puoi scrivere: "from pandas import read_csv" per importare solo la funzione read_csv. Attualmente in JMP importo sempre un intero file JSL con molte funzioni definite al suo interno e penso che sarebbe meglio importare solo le funzioni di cui ho bisogno per motivi di chiarezza (e forse prestazioni).
Grazie
Richard
Accesso ai datiRi: Come includere funzioni specifiche invece dell'intero scriptEffettivamente funziona, grazie mille!Ri: Come includere funzioni specifiche invece dell'intero scriptScusa il mio errore, è necessario un nome expr( funzione quando si copia la funzione.Ecco un esempio rivisto:
incluso.jsl:
f = function({x,y}, x + y);Script per caricare la funzione:
names default to here(1);
//load the new file in a local here namespace
Eval( Eval Expr( local here(
include("included.jsl");
//Reference the original script's here namespace in this new here namespace
//Eval, Eval Expr, and Expr cause the namespace("here") to be evaluated
//outside of this 'local here' context.
//from the other.
ns = Expr( namespace("here") );
//copy and functions you want to keep
ns:f = Name expr( here:f );
) ) );
//Now functions are in here namespace
f(1,2);Ri: Come includere funzioni specifiche invece dell'intero scriptGrazie per il tuo aiuto, questo funziona sicuramente per le funzioni senza alcun argomento.
Sfortunatamente mi imbatto in un errore durante il tentativo di importare una funzione con due argomenti, l'errore indica che non fornisco alcun argomento quando la funzione ne richiede 2 (il che è vero). Ecco il codice di esempio:
names default to here(1);
MyRejet = 1;
Lot_nom = "G123456";
//load the new file in a local here namespace
Eval( Eval Expr( local here(
Include("include.jsl");;
//Reference the original script's here namespace in this local here namespace
//Eval, Eval Expr, and Expr cause the namespace("here") to be evaluated
//outside of this 'local here' context.
ns = Expr( namespace("here") );
print(ns);
//copy and functions you want to keep
ns:DataExtraction = here:DataExtraction;
) ) );
//Now functions are in this namespace
DataExtraction(Lot_nom, MyRejet);Sapete dov'è l'errore? Ho provato a specificare gli argomenti durante la copia delle funzioni ma non sembra risolvere il problema.
Grazie
Richard
Ri: Come includere funzioni specifiche invece dell'intero scriptNon conosco nulla di così semplice come offre Python, ma qui ci sono due opzioni che portano a termine il lavoro:
Considera un file chiamato included.jsl:
a = function({}, 1);
b = function({}, 2);Per caricare la funzione direttamente nel contesto del tuo script:
names default to here(1);
//load the new file in a local here namespace
Eval( Eval Expr( local here(
include("included.jsl");
//Reference the original script's here namespace in this local here namespace
//Eval, Eval Expr, and Expr cause the namespace("here") to be evaluated
//outside of this 'local here' context.
ns = Expr( namespace("here") );
//copy and functions you want to keep
ns:a = here:a;
) ) );
//Now functions are in this namespace
a();
Oppure, per mantenere la funzione in uno spazio dei nomi separato:
names default to here(1);
//create namespace to hold functions you want to keep from included file
ns = new namespace();
//load the new file in a local here namespace
Eval( Eval Expr( local here(
include("included.jsl");
//Reference the ns namespace in this new here namespace
ns = Expr( ns );
//pick and choose any functions you want to keep
ns:a = here:a
) ) );
//Now either call the functions from the ns namespace
ns:a();
//or copy them to the here namespace
a = ns:a;
a();
Ri: Come includere funzioni specifiche invece dell'intero scriptNon sono a conoscenza di alcun modo per includere solo un sottoinsieme da un file di inclusione.