I have a working Python program (nested loop).
When the file runs:
1- Starts from first CSV file, reads first row (within a given range, e.g. 2 rows), use the data to run the function.
2- After some delay, it reads the next row and runs the function.
3- When it is done with ranges of rows on the first CSV file, after another delay, it uses the next CSV file to read the rows (within the same given range), do the same thing, when done it goes to the next CSV file, and so on until the last CSV file.
Here is the program that works fine:
sample CSV file:
** EDITED **
The code above works fine, but the problem is:
when you run the file again, it reads the same data from CSV files, (in my example the given range is 2 rows, so every time I run it, it reads row 1 and row 2).
I want the code to use other rows as well when it runs again, within the same given range of course.
So I want to add another loop to it, which each time file runs, it starts from the next set of rows that have not been used.
as an example, if the ranges of rows are set to 2, it means it should read only 2 rows of data from each CSV file that are in
.
1- file runs (first time), reads row 1, uses the data, some delay then read row 2 uses the data, some delay, goes to next CSV file, the same process until the last CSV file.
2- file runs for the second time, it should start to use from row 3, uses the data, some delay then it should read row 4, uses the data, some delay goes to the next CSV file, the same process again until the last CSV file.
the functionality of the code remains the same.
The whole process is to read data from CSV files and run the function, no writing to CSV files.
Appreciate your help to make this work.
When the file runs:
1- Starts from first CSV file, reads first row (within a given range, e.g. 2 rows), use the data to run the function.
2- After some delay, it reads the next row and runs the function.
3- When it is done with ranges of rows on the first CSV file, after another delay, it uses the next CSV file to read the rows (within the same given range), do the same thing, when done it goes to the next CSV file, and so on until the last CSV file.
Here is the program that works fine:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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: next (f) # skip first header line for _ in range ( 1 , 3 ): line = next (f) img_url, title_1, desc_1, link_1 = map ( str .strip, line.split( ';' )) zzz.func1(img_url = img_url, title_1 = title_1, desc_1 = desc_1, link_1 = link_1, B_id = B_id = pair[ 'id' ], s_id = s_id) time.sleep( 25 ) |
Quote:img_url,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
** EDITED **
The code above works fine, but the problem is:
when you run the file again, it reads the same data from CSV files, (in my example the given range is 2 rows, so every time I run it, it reads row 1 and row 2).
I want the code to use other rows as well when it runs again, within the same given range of course.
So I want to add another loop to it, which each time file runs, it starts from the next set of rows that have not been used.
as an example, if the ranges of rows are set to 2, it means it should read only 2 rows of data from each CSV file that are in
1 |
path_id_map = [] |
1- file runs (first time), reads row 1, uses the data, some delay then read row 2 uses the data, some delay, goes to next CSV file, the same process until the last CSV file.
2- file runs for the second time, it should start to use from row 3, uses the data, some delay then it should read row 4, uses the data, some delay goes to the next CSV file, the same process again until the last CSV file.
the functionality of the code remains the same.
The whole process is to read data from CSV files and run the function, no writing to CSV files.
Appreciate your help to make this work.