I am new to Python, I want to make a function work using data from multiple columns CSV files, one row by one row with some delay in between each run.
This is want to achieve:
1- Read from first CSV file within a range ( e.g. row 0 to row 3)
2- Use cell data of one row, to fill the right parameter area in the function, and run the function, some delay, then it goes to the next row, and run,
3- Some delay again, then it goes to next CSV file, do the same, until the last CSV file.
I have the tried the following code, but it does not work.
The following code works fine with one column CSV file, but using data from multiple columns, I am not sure how to pass the right data to the right parameter inside the function.
there are 4 parameters that I want to get the value from csv file from the column with the same header name:
img_path
title_1
desc_1
link_1
sample csv file:
when I run this I get error on "return" I get:(unexpected indent).
I appreciate your help to make it work
This is want to achieve:
1- Read from first CSV file within a range ( e.g. row 0 to row 3)
2- Use cell data of one row, to fill the right parameter area in the function, and run the function, some delay, then it goes to the next row, and run,
3- Some delay again, then it goes to next CSV file, do the same, until the last CSV file.
I have the tried the following code, but it does not work.
The following code works fine with one column CSV file, but using data from multiple columns, I am not sure how to pass the right data to the right parameter inside the function.
there are 4 parameters that I want to get the value from csv file from the column with the same header name:
img_path
title_1
desc_1
link_1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
from abc.zzz import xyz path_id_map = [ { 'path' : 'file1.csv' , 'id' : '12345678' }, { 'path' : 'file2.csv' , 'id' : '44556677' } { 'path' : 'file3.csv' , 'id' : '33377799' } { 'path' : 'file4.csv' , 'id' : '66221144' }] s_id = None for pair in path_id_map: with open (pair[ 'path' ], 'r' ) as f: for i in range ( 0 , 3 ): zzz.func1(img_path = f.readline().rstrip( ',' ), title_1 = f.readline().rstrip( ',' ), desc_1 = f.readline().rstrip( ',' ), link_1 = f.readline().rstrip( ',' ), B_id = pair[ 'id' ], s_id = s_id) return zzz.func1(img_file = img_path, title_1 = title_1, desc_1 = desc_1, link_1 = link_1, B_id = B_id, s_id = s_id) time.sleep( 25 ) |
Quote:img_path,desc_1 title_1,link_1
site.com/image22.jpg,someTitle,description1,site1.com
site.com/image32.jpg,someTitle,description2,site2.com
site.com/image44.jpg,someTitle,description3,site3.com
when I run this I get error on "return" I get:(unexpected indent).
I appreciate your help to make it work