Python Forum
How do I add another loop to my nested loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I add another loop to my nested loop
#2
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)
Reply


Messages In This Thread
RE: How do I add another loop to my nested loop - by tinh - Dec-25-2020, 03:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need an alternative to brute force optimization loop jmbonni 5 1,538 Jun-05-2024, 02:21 AM
Last Post: stevejobb
  Need help with a while loop ampereap 4 296 May-31-2024, 02:25 PM
Last Post: ampereap
  problem program runs in a loop jasserin 0 231 May-18-2024, 03:07 PM
Last Post: jasserin
  [SOLVED] Loop through directories and files one level down? Winfried 3 468 Apr-28-2024, 02:31 PM
Last Post: Gribouillis
  Loop through all files in a directory? Winfried 10 887 Apr-23-2024, 07:38 PM
Last Post: FortuneCoins
  for loop not executing Abendrot47 2 402 Apr-09-2024, 07:14 PM
Last Post: deanhystad
  Re Try loop for "net use..." failures tester_V 10 878 Mar-02-2024, 08:15 AM
Last Post: tester_V
  File loop curiously skipping files - FIXED mbk34 10 1,138 Feb-10-2024, 07:08 AM
Last Post: buran
  Optimise multiply for loop in Python KenBCN 4 650 Feb-06-2024, 06:48 PM
Last Post: Gribouillis
  Basic binary search algorithm - using a while loop Drone4four 1 539 Jan-22-2024, 06:34 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020