如何包含特定函数而不是整个脚本你好,
有没有办法从 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();
回复:如何包含特定函数而不是整个脚本我不知道有什么方法可以仅包含包含文件中的子集。