Transform an array to string in python

4

I'm trying to convert an array to a string and add the "|" at the beginning and end of each field

Below the example array

['', 'C170', '1', '14879', '', '1,00000', 'UN', '29,99', '0,00', '1', '060', '1407',
 'NE09', '0,00', '0,00', '0,00', '0,00', '0,00', '0,00', '0', '49', '', '0,00', '0,00',
 '0,00', '99', '0,00', '0,00', '', '', '0,00', '99', '0,00', '0,00', '', '', '0,00', 
'3010107010057', '\n']
    
asked by anonymous 19.01.2017 / 09:51

1 answer

3
"|".join(a)

produces a string with the elements separated by "|"

'|C170|1|14879||1,00000|UN|29,99|0,00|1|..... 3010107010057|\n'

Putting together "|" at the beginning and end:

"|" +  "|".join(a) + "|"

or

 "|%s|" %   "|".join(a)

gives

'||C170|1|14879||1,00000|UN|29,99|0,00|1|..... 3010107010057|\n|'

Is this what you want?

    
19.01.2017 / 10:12