将现有代码片段包括到Python/IronPython中

2024-06-16 10:17:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在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(); 
}

Tags: theforindexinformationvarstepoperationint