【问题标题】:Convert an array to a string in Iron Python在 Iron Python 中将数组转换为字符串
【发布时间】:2014-10-02 16:12:08
【问题描述】:

我对 Iron Phyton 非常非常陌生,我正在尝试创建一个脚本,允许用户在下拉列表中选择“全部”功能。这是我到目前为止的代码,但我收到一条错误消息,指出“属性值的类型 'System.String[]' 与预期的 'System.String' 类型不匹配”

我在 Spotfire 中编码,我不能将数组存储在属性中,因为只允许使用字符串。我已经搜索过我可以使用 ', '.join(mylist)

但我就是不知道放在哪里...请帮忙,谢谢..代码如下

from System import Array
from Spotfire.Dxp.Data import IndexSet
from Spotfire.Dxp.Data import DataValueCursor

#Get access to the Column from which we want to get the values from
myCol = Document.ActiveDataTableReference.Columns["Business Group"]

rowCount = Document.ActiveDataTableReference.RowCount
rowsToInclude = IndexSet(rowCount,True)


#Create a cursor to the Column we wish to get the values from
cursor1 = DataValueCursor.CreateFormatted(Document.ActiveDataTableReference.Columns ["BusinessGroup"])


strArray = Array.CreateInstance(str,rowCount)


#Loop through all rows, retrieve value for specific column, and add value into array
 for  row in  Document.ActiveDataTableReference.GetRows(rowsToInclude,cursor1):
 rowIndex = row.Index
 value1 = cursor1.CurrentValue
 strArray[rowIndex-1] = value1   

#Set property to array created above
myCol.Properties.SetProperty("BusinessGroup",strArray)

【问题讨论】:

    标签: arrays ironpython spotfire


    【解决方案1】:

    假设您的代码在 sn-p 的最后一行失败,因为 "BusinessGroup" 应该是一个字符串而不是字符串数组,您可以使用以下方式加入:

    myCol.Properties.SetProperty("BusinessGroup", ', '.join(strArray))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-09
      • 2020-04-06
      • 2018-09-19
      相关资源
      最近更新 更多