Python ValueError:名称';受试者身份[个人/群体]和#x27;列集合中已存在。参数名称:value

Python ValueError:名称';受试者身份[个人/群体]和#x27;列集合中已存在。参数名称:value,python,ironpython,spotfire,Python,Ironpython,Spotfire,下面的代码返回错误: 我没有发现这个错误 import datetime from Spotfire.Dxp.Data import IndexSet from Spotfire.Dxp.Data import RowSelection from Spotfire.Dxp.Data import IndexSet, DataValueCursor, RowSelection from Spotfire.Dxp.Data.DataType import DateTime dictTable =

下面的代码返回错误: 我没有发现这个错误

import datetime
from Spotfire.Dxp.Data import IndexSet
from Spotfire.Dxp.Data import RowSelection
from Spotfire.Dxp.Data import IndexSet, DataValueCursor, RowSelection
from Spotfire.Dxp.Data.DataType import DateTime

dictTable = Document.Data.Tables['Column renaming mapping']
dictionary = dict()
key = 0
value = 0
colNum = 0
cursorKeys = DataValueCursor.CreateFormatted(dictTable.Columns['PDW short name'])
cursorValues = DataValueCursor.CreateFormatted(dictTable.Columns['PDW long name'])
rowCount = dictTable.RowCount
rowsToInclude = IndexSet(rowCount,True)

for row in dictTable.GetRows(rowsToInclude,cursorKeys,cursorValues):

    rowIndex = row.Index
    key =   cursorKeys.CurrentValue
    print key
    val    = cursorValues.CurrentValue
    print val
    dictionary[key] = val

for table in Document.Data.Tables:

    for col in table.Columns:

        if col.Name in dictionary:
            col.Name = dictionary[key]
我肯定做错了什么。 我的目标是迭代tru所有表并修改某些列的命名。 我想按照我称之为discTable的表修改它们

根据代码生成的内容添加完整错误和打印结果

TSRECID
TS Record ID
STUDYKEY
PDW unique ID
INSERTDT
Record entry date
UPDATEDT
Record update date
AUDITID
Transaction unique ID
SPONSOR
Sponsor
PSMSNAME
Preclinical Study Management System
STUDYID
Study ID
STUDYTITLE
Study title
PROJID
PIMS project ID
PROJDESC
PIMS project description
ETHICPROJ
PIMS ethical project
STUDYCAT
PIMS study category
STUDYTP
PIMS study type
PROTSTATUS
PIMS protocol status
STDPROTID
PIMS standard protocol ID
RATIONALE
Scientific Rationale
PRIMOBJECTIVE
Primary objective
SECOBJECTIVE
Secondary objective
NBSUBJECTS
Number of subjects
SUBLVLID
Subject identification [Individual/Pool]
Traceback (most recent call last):
  File "Spotfire.Dxp.Application.ScriptSupport", line unknown, in ExecuteForDebugging
  File "<string>", line 31, in <module>
  File "Spotfire.Dxp.Data", line unknown, in set_Name
ValueError: The name 'Subject identification [Individual/Pool]' already exists in the column collection.
Parameter name: value

System.ArgumentException: The name 'Subject identification [Individual/Pool]' already exists in the column collection.
Parameter name: value
   at Spotfire.Dxp.Data.DataColumn.set_Name(String value)
   at _stub_$25##25(Closure , CallSite , Object , Object )
   at Microsoft.Scripting.Actions.MatchCaller.Call2[T0,T1,TRet](Func`4 target, CallSite site, Object[] args)
   at Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)
   at Microsoft.Scripting.Actions.UpdateDelegates.Update2[T,T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   at <module>$4##4(Closure , Scope , LanguageContext )
   at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
   at Spotfire.Dxp.Application.ScriptSupport.IronPythonScriptEngine.ExecuteForDebugging(String scriptCode, Dictionary`2 scope, Stream outputStream)
TSRECID
TS记录ID
书房
PDW唯一ID
INSERTDT
记录录入日期
更新
记录更新日期
试听
事务唯一ID
赞助商
赞助商
PSMSNAME
临床前研究管理系统
研究
研究ID
书斋
书名
项目
PIMS项目ID
PROJDESC
PIMS项目描述
伦理项目
PIMS道德项目
研究中心
PIMS研究类别
研究计划
PIMS研究类型
原生状态
PIMS协议状态
STDPROTID
PIMS标准协议ID
根本原因
科学原理
首要目标
主要目标
副目标
次要目标
NB科目
受试者人数
子叶
受试者身份[个人/群体]
回溯(最近一次呼叫最后一次):
文件“Spotfire.Dxp.Application.ScriptSupport”,行未知,位于ExecuteForDebug中
文件“”,第31行,在
文件“Spotfire.Dxp.Data”,行未知,在集合名称中
ValueError:列集合中已存在名称“主题标识[个人/池]”。
参数名称:value
System.ArgumentException:列集合中已存在名称“主题标识[个人/池]”。
参数名称:value
位于Spotfire.Dxp.Data.DataColumn.set_Name(字符串值)
at _stub_uu$25##25(闭包、调用站点、对象、对象)
在Microsoft.Scripting.Actions.MatchCaller.Call2[T0,T1,TRet](Func`4目标,CallSite站点,对象[]args)
位于Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(对象[]args)
在Microsoft.Scripting.Actions.UpdateDelegates.Update2[T,T0,T1,TRet](调用站点,T0 arg0,T1 arg1)
价格为$4##4(闭包、范围、语言上下文)
在Microsoft.Scripting.SourceUnit.Execute(作用域范围,ErrorSink ErrorSink)
在Spotfire.Dxp.Application.ScriptSupport.IronPythonScriptEngine.ExecuteForDebugging(字符串脚本代码,Dictionary`2作用域,流输出流)

如果尝试将列重命名为表中已使用的列(给定表中的两列不能具有相同的名称),则会出现此错误。我建议找出哪个表导致了错误,并再次检查是否已经有一个名为“Subject identification[Individual/Pool]”的列


谢谢你,杰克

Hi Jacek-如果尝试将列重命名为表中已使用的列(给定表中的两列不能具有相同的名称),则会出现此错误。我建议找出哪个表导致了错误,并仔细检查是否已经有一个名为“主题标识[个人/池]”的列@Monte_fisto您可以将此评论作为一个答案。通过将col.Name=dictionary[key]修改为col.Name=dictionary[col.Name],代码得到了修复,但您的答案有所帮助