在.NET4.0上的IronPython2.7.5中将数组连接到一个数组中

在.NET4.0上的IronPython2.7.5中将数组连接到一个数组中,python,.net,arrays,list,ironpython,Python,.net,Arrays,List,Ironpython,在IronPython 2.7.5中,我有一个返回字符串数组的函数(由其他人设计的backbox) 该函数在循环中调用。我需要逐个连接返回的数组。最后一个类型还必须是字符串数组 更新 我的代码: def Myfunction(): in a For Loop: data_array = Anotherfunction() final_data_array += data_array ThirdFunction(final_d

在IronPython 2.7.5中,我有一个返回字符串数组的函数(由其他人设计的backbox)

该函数在循环中调用。我需要逐个连接返回的数组。最后一个类型还必须是字符串数组

更新

我的代码:

   def Myfunction():
      in a For Loop:
         data_array = Anotherfunction()
         final_data_array += data_array  

      ThirdFunction(final_data_array) # the final data type MUST be array
  from array import array 
  tt = ["abc", "def"]
  array(','.join(tt)) 
我不知道如何对数组进行连接

因此,我将数组转换为list,然后将它们连接起来

最后,我需要在.NET4.0上的IronPython 2.7.5中将最终列表(包含所有restuls)转换为数组(它必须是数组,因为它将用作lib函数的输入参数)

我的代码:

   def Myfunction():
      in a For Loop:
         data_array = Anotherfunction()
         final_data_array += data_array  

      ThirdFunction(final_data_array) # the final data type MUST be array
  from array import array 
  tt = ["abc", "def"]
  array(','.join(tt)) 
我得到一个错误:

 Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 TypeError: expected character, got str
  Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  TypeError: expected str, got list
我得到一个错误:

 Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 TypeError: expected character, got str
  Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  TypeError: expected str, got list
但是,这只是为了性格。我需要

  <type 'Array[str]'>


有什么建议吗?感谢

数组是一个等待实例化的对象,您不应该使用它

见:

如果由于类型不同而无法将列表与数组连接起来

连接列表或数组很容易,只需尝试:

名单:

阵列:

from array import array
a = array('i') # i = int
b = array('i') # read the table in the documentation for understand ('letter')
a = 1,2
b = 3,4
print a+b
>>>(1,2,3,4)
或“str” 使用数组('u')o数组('c'))

如果你想作为名单

a = array('c')
a = ['lel', 'hixD']
print a
>>>['lel', 'hixD']
print type(a)
>>><type 'list'>
a=数组('c')
a=['lel','hixD']
打印
>>>['lel','hixD']
打印类型(a)
>>>
注 “u”类型代码对应于Python的unicode字符。在窄Unicode版本上,这是2字节,在宽版本上,这是4字节

加入str:

ss = ', '.join(tt) # result: 'abc, def'
使用字符串“char”或“unicode”初始化数组:

s2 = array('c',ss) # array('c', 'abc, def')

我不知道它是否是您想要的。

“,”。join(tt)”的类型是str而不是array。谢谢,但是array('c')仅用于字符。我需要。我认为可以使用数组('u'),@Lily>>“'u'类型码对应于Python的unicode字符。在>>>窄Unicode构建上这是2个字节,在宽构建上这是4个字节。数组('u'),我得到了一个元组,>>>a=array('u')>>>b=array('u')>>>a=“abc”,“def”>>>b=“fgt”,“typ”>>a+b('abc','def','fgt','typ')>>>>类型(a+b)使用a=array('c'),然后使用a=['hiworld','xDDD']
a=array('I'))
然后
a=1,2
没有任何意义。首先创建一个长度为0的数组并将其称为
a
,然后创建一个长度为2的元组并将其称为
a
。为什么要使用数组?请参阅OP中的更新。模块数组有一个特定的类型代码,如中所示。模块代表一个数组(或字符串)的基本值,你应该考虑模块<代码> NoMPy < /代码>或列表为您的目的。