2016-03-26 1 views
0

In IronPython 2.7.5 habe ich eine Funktion (eine von anderen entworfene Backbox), die Array von String zurückgeben.verketten Arrays in einem Array in IronPython 2.7.5 auf .NET 4.0

Die Funktion wird in einer Schleife aufgerufen. Ich muss das zurückgegebene Array einzeln verketten. Der letzte Typ muss auch ein String-Array sein.

UPDATE

Mein Code:

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 

Ich weiß nicht, wie für die Array-Verkettung zu tun.

Also, ich konvertiere das Array zu Liste und verketten sie dann.

Schließlich muss ich die endgültige Liste (mit allen restruls) in ein Array (es muss Array sein, da es als Eingabe-Argument für eine lib-Funktion verwendet werden wird) in IronPython 2.7.5 auf .NET 4.0 konvertieren.

Mein Code:

from array import array 
    tt = ["abc", "def"] 
    array(','.join(tt)) 

Ich habe Fehler:

Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
TypeError: expected character, got str 

Für Code:

from array import array 
tt = ["abc", "def"] 
array(tt) 

Ich habe Fehler:

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    TypeError: expected str, got list 

Ich kann numpy und andere Pakete nicht verwenden.

Oder, wie Arrays zu einem Array verketten?

ich auch versucht:

array('c') 

aber, es nur für Charakter ist. Ich brauche

<type 'Array[str]'> 

Irgendwelche Vorschläge?Dank

+0

',' .join (tt) 's Typ ist str nicht Array. – Lily

Antwort

0

Array ist ein Objekt instanziert zu warten, sollten Sie es nicht

nachschauen: https://docs.python.org/2/library/array.html

wenn Sie schräges verketten Liste mit Array, weil es verschiedene Arten

Concatenate eine Liste oder Arrays ist einfach, versuchen sie es nur:

Liste:

a = [1,2] 
b = [3,'hey'] 
print a+b 
>>>[1,2,3,'hey'] 

Arrays:

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) 

oder 'str' Verwendung array ('u') o array ('C')

wenn will als Liste

a = array('c') 
a = ['lel', 'hixD'] 
print a 
>>>['lel', 'hixD'] 
print type(a) 
>>><type 'list'> 

Note The 'u' typecode corresponds to Python’s unicode character. On narrow Unicode builds this is 2-bytes, on wide builds this is 4-bytes.

+0

danke, aber, Array ('c') ist nur für den Charakter. Ich brauche . – Lily

+0

Ich denke, dass könnte Array ('u'), @ Lily >>> Der 'u' Typcode entspricht Python Unicode-Zeichen. Bei >>> Narrow-Unicode-Builds ist dies 2 Byte, bei Wide-Builds sind es 4 Byte. – Milor123

+0

Array ('u'), ich habe ein Tupel, >>> a = Array ('u') >>> b = Array ('u') >>> a = "abc", "def" >>> b = "fgt", "typ" >>> a + b ('abc', 'def', 'fgt', 'typ') >>> typ (a + b) Lily

0

Beitreten str:

ss = ', '.join(tt) # result: 'abc, def' 

initialisieren Array mit „char“ oder „Unicode“ mit der Zeichenfolge:

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

Ich weiß nicht, ob es was Sie wollen.

+0

Bitte beachten Sie die UPDATE in OP. – Lily

+0

Modul-Array hat einen spezifischen Typcode, wie Sie [@ Milor123] (http://stackoverflow.com/users/4941927/milor123) im [link] (https://docs.python.org/2/library/array .html). Das Modul repräsentiert ein Array (oder eine Kette) von Grundwerten, Sie sollten das Modul 'numpy' oder die Liste für Ihren Zweck betrachten. –