python - concatenate elements of list with PIPE Delimiter -


i require on below code. code following.

execute sql query , output of sql query mix of strings,int , date. ie

10001,new york,corp,1,20151001 10002,new york,corp,1,20151001 

etc.

the expectation want concatenate each record of sql output , write file.

10001|new york|corp|1|20151001\n 10002|new york|corp|1|20151001\n 

below code.

import cx_oracle import os  result = cur.execute(qry)  # -> execute sql query. le.extend(result)  # output of le , le -> type list  le = [(10001,u'new york','corp',1,20151001),(10002,u'new york','corp',1,20151001)]  final_data = [] final_data.extend('|'.join(w) w in le) 

getting error above statement.

typeerror: sequence item 1: expected string or unicode, int found 

i tried this

final_data.extend('|'.join(str(w)) w in le) 

but not getting desired output, 10001|new york|corp|1|20151001\n

highly appreciate if on this.

thanks, bala

final_data = ["|".join(map(unicode, w)) + "\n" w in le] 

then can either use "".join(final_data) create single string written file, or write each element in final_data file sequentially, depending on need.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -