How to fill parameter with data from multiple columns CSV file - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to fill parameter with data from multiple columns CSV file (/thread-31588.html) |
How to fill parameter with data from multiple columns CSV file - greenpine - Dec-21-2020 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 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)sample csv file: Quote:img_path,desc_1 title_1,link_1 when I run this I get error on "return" I get:(unexpected indent). I appreciate your help to make it work RE: How to fill parameter with data from multiple columns CSV file - Larz60+ - Dec-21-2020 see this post I made earlier today: https://python-forum.io/Thread-MDB-to-CSV-Specific-columns?pid=133556#pid133556 |