Need a Python script with MySQl : read value from csv, fetch in db and write it in another file -


i new python scripting. using python 3 , want script below scenario.

1 csv file has 2k records, 1 column present.

 eg :  name abc def ghi 

i want store these strings in list , use them fetch in table using mysql 1 one using loop.

say row in reader:

query=("select * table name=%s", (row)) name_list =cursor. fetchall()

now again after incoming records store on name_list, want write them in csv file

please let me know if not clear.

thanks valuable in advance.

regards, sukumar

updated

below tried. facing problem in data type conversion. query asking string value value present byte. totally new kindly ignore if wrong

import csv   import mysqldb  db = mysqldb.connect("localhost", "root", "usr_name", "pwd")  cursor = db.cursor()  open("input_names.csv") f:      reader = csv.reader(f)      row in reader:          name_list = list(reader)          query = ("select * name=%s", (i))          cursor.execute(query)          details_list = cursor.fetchall() db.close()  details = open("output.csv",'wb')  wr = csv.writer(details, dialect='excel')  item in details_list:      wr.writerow(item) 

import pandas pd names_df = pd.read_csv('names.csv') names_lst = list(names_df['names])  sql_df = pd.dataframe() names in names_lst:     sql_df = sql_df.append(pd.read_sql('select * table name =' + names, con = db_conn_params) 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -