Dec-25-2020, 03:40 AM
Maybe this could help:
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 from os.path import dirname as fdir from os.path import join as fjoin from os.path import exists as fexist scriptdir = fdir(__file__) currentinfo = fjoin(scriptdir, 'currentinfo.py') if fexist(currentinfo): with open(currentinfo, 'r', encoding='utf-8') as fpt: script = fpt.read() exec(script, globals()) else: foff = 0 rfrom = 1 rto = 3 for pair in path_id_map: with open(pair['path'], 'r') as f: if foff == 0: next(f) # skip first header line else: f.seek(foff) for _ in range(rfrom, rto): line = next(f) foff = f.tell() 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) with open(currentinfo, 'w', encoding='utf-8') as fpt: fpt.writelines('foff =', foff) fpt.writelines('rfrom =', rto) fpt.writelines('fto =', rto + 2)