首页 > 解决方案 > 在 Python/IronPython 中包含现有代码片段

问题描述

我想在 TIBCO Spotfire 中将以下代码包含到我的 IronPython/Python 脚本中。有人对此有解决方案吗?我是 IronPython/Python 和 Spotfire 的初学者。提前谢谢了!

问候菲利克斯

{
    var table = application.Document.Data.Tables.DefaultTableReference;
    var sourceView = table.GenerateSourceView();

    Func<StringBuilder, DataOperation, string, int> dumpOperationInfoRecursively = null;
    dumpOperationInfoRecursively = (stringBuilder, operation, indentationSpaces) =>
    {
        int step = 1;

        // If the operation had any inputs, then first print the first input's information.
        if (operation.Inputs.Count > 0)
        {
            step = dumpOperationInfoRecursively(stringBuilder, operation.Inputs[0], indentationSpaces);
            step++;
        }

        // Print information about this operation.
        stringBuilder.AppendFormat("{0}{1}. {2}\r\n", indentationSpaces, step, operation.DisplayName);

        // Output names of any transformations we have.
        IList<DataTransformation> transformations = new List<DataTransformation>();
        var ost = sourceView.OperationsSupportingTransformations.FirstOrDefault(op => op.DataOperation == operation);
        if (ost != null)
        {
            transformations = ost.GetTransformations();
        }

        int index = 0;
        foreach (var transformation in transformations)
        {
            stringBuilder.AppendFormat("{0}{1}. {2}\r\n", indentationSpaces + "    ", Convert.ToChar('a' + index), transformation.Name);
            index++;
        }

        // Last, print information about additional inputs. (Typically the
        // additional data for an Add Rows or Add Columns operation.)
        for (int i = 1; i < operation.Inputs.Count; ++i)
        {
            dumpOperationInfoRecursively(stringBuilder, operation.Inputs[i], indentationSpaces + "    ");
        }

        // Returns the step number for this operation.
        return step;
    };

    var sb = new StringBuilder();
    dumpOperationInfoRecursively(sb, sourceView.LastOperation, string.Empty);

    return sb.ToString(); 
}

标签: pythonironpythonspotfire

解决方案


正如 Oliver 所说,这不是 python,所以你不能在 Spotfire 中将它导入 IronPython。如果要达到相同的结果,则需要编写具有相同功能的 python 脚本。也就是说,这看起来像是您正在尝试重写 Concatenate() 函数,尽管它不是很清楚,而且我不确定您打算将什么用作输入或您打算将输出放在哪里。你想通过导入这个来完成什么?正如我所提到的,看起来答案是“使用 Concatentate()”,但我认为如果这不是您想要的,我们需要更多信息。


推荐阅读