简体   繁体   English

在Spotfire中使用IronPython存储和调用表达式

[英]Storing and Calling Expressions with IronPython in Spotfire

Is there anyway to store an expression in an IronPython script in Spotfire, and then call on it later to simplify my scripts where I am adding a bunch of calculated columns? 无论如何在Spotfire中的IronPython脚本中存储表达式,然后稍后调用它来简化我添加一堆计算列的脚本? Some of my expressions are simply (A+B), but i am also trying to see if it is possible to store an if then "case statement" as an expression 我的一些表达式只是(A + B),但我也试图看看是否可以将if case“case statement”存储为表达式

For example: 例如:

expression1 = [VarA] * 3.289 expression1 = [VarA] * 3.289

expression2 ~ (VarA] / [VarB]) * 23.33 表达式2~(VarA)/ [VarB])* 23.33

expression3 = Case When [VarA] = 1 Then "Blue" Else "Red" End expression3 =当[VarA] = 1时的情况然后“蓝色”否则“红色”结束


example script (this works): 示例脚本(这可行):

from Spotfire.Dxp.Data import CalculatedColumn
cols = Document.Data.Tables["MyTable"].Columns
cols.AddCalculatedColumn("NewColumn1","[VarA] * 3.289");

Example of what I'd like to do: 我想做的例子:

from Spotfire.Dxp.Data import CalculatedColumn
cols = Document.Data.Tables["MyTable"].Columns
cols.AddCalculatedColumn("NewColumn1","expression1");
cols.AddCalculatedColumn("NewColumn2","expression2");
cols.AddCalculatedColumn("NewColumn3","expression3");

I mean maybe I'm not understanding you but I think just make expression1 a variable like you were trying to do. 我的意思是也许我不是在理解你,但我认为只需将expression1变成一个像你想要的那样的变量。 Make sure you use quotation marks for strings and don't use them for variables. 确保对字符串使用引号,不要将它们用于变量。

expression1 = "[varA]*3.289"
cols.AddCalculatedColumn("NewColumn1",expression1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM