如何包含特定函數而不是整個腳本你好,
有沒有辦法從 JSL 文件中僅導入特定函數?
例如,在 python 中,您可以編寫:“from pandas import read_csv”以僅導入 read_csv 函數。 目前在 JMP 中,我總是導入一個完整的 JSL 文件,其中定義了許多函數,並且我認為為了清晰起見(也許還有性能),最好只導入我需要的函數。
謝謝
理查德
數據存取回复:如何包含特定函數而不是整個腳本確實有效,非常感謝!回复:如何包含特定函數而不是整個腳本抱歉我的錯誤,複製函數時需要一個名稱 expr( 函數。這是一個修改後的示例:
包含.jsl:
f = function({x,y}, x + y);加載函數的腳本:
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);回复:如何包含特定函數而不是整個腳本感謝您的幫助,這絕對適用於沒有任何參數的函數。
不幸的是,當我嘗試導入帶有兩個參數的函數時遇到錯誤,該錯誤表明當函數需要其中兩個參數時我沒有給出任何參數(這是正確的)。 這是示例代碼:
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);你知道錯誤在哪裡嗎? 我嘗試在復制函數時指定參數,但似乎沒有解決問題。
謝謝
理查德
回复:如何包含特定函數而不是整個腳本我也不知道有什麼像 python 提供的那樣簡單,但這裡有兩個選項可以完成工作:
考慮一個名為included.jsl的文件:
a = function({}, 1);
b = function({}, 2);要直接在腳本上下文中加載該函數:
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();
或者,將該函數保留在單獨的命名空間中:
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();
回复:如何包含特定函數而不是整個腳本我不知道有什麼方法可以僅包含包含文件中的子集。