while 循环与 try/exception 保持循环直到读取 df 的所有行/忽略异常

while loop with try/exception stay in loop until read all rows of df / ignore exception

这是Python卡在异常循环中的一段。我读到 and and many more and unfortunately could not find the answer I am looking for. It works fine until it gets stuck in exception for i=8 (i.e. the git_url 由所有者存档)。我该如何解决?我不希望它在 i=8 时 break/get_stuck 因为它仍然需要读取其余部分。

i=7
while i<10:
  try:
    Repo.clone_from(df.git_url[i],repo_dir) #clone repositores for each url
  except:
    print("error")
    continue
  else:
      for f in glob.iglob("repo_dir/**/*.rb"):
        txt = open(f, "r") 
        # let's say txt is a code file that I want to extract data from 
        for line in txt:
            print(line)  
  shutil.rmtree(repo_dir)
  os.makedirs(repo_dir)
  i+=1  

一旦调用了continue,它将跳回到调用i += 1之前的顶部。尝试将该语句向上移动,例如:

i=7
while i<10:
  try:
    Repo.clone_from(df.git_url[i],repo_dir) #clone repositores for each url
  except:
    print("error")
    i += 1
    continue
  else:
      for f in glob.iglob("repo_dir/**/*.rb"):
        txt = open(f, "r") 
        # let's say txt is a code file that I want to extract data from 
        for line in txt:
            print(line)  
  shutil.rmtree(repo_dir)
  os.makedirs(repo_dir)
  i += 1  

这样它就不会卡在有问题的迭代中,让我知道这是怎么回事:)