Вы можете поместить индекс в свой цикл for. Вы можете использовать модуль или сбросить каждый раз:
count = 0
for identifier in identifiers:
if count==10:
action()
count = 0
count +=1
result = sh.download(identifier, args.output)
if 'err' in result:
logger.debug('%s', result['err'])
else:
logger.debug('Successfully downloaded file with identifier %s', identifier)
Если вы хотите считать только успешные итерации, вы должны поместить код в блок else
:
count = 0
for identifier in identifiers:
result = sh.download(identifier, args.output)
if 'err' in result:
logger.debug('%s', result['err'])
else:
logger.debug('Successfully downloaded file with identifier %s', identifier)
if count == 10:
action()
count = 0
count +=1
Вы также можете использовать enumerate
:
for count, identifier in enumerate(identifiers):
if count%10 == 0:
action()
result = sh.download(identifier, args.output)
if 'err' in result:
logger.debug('%s', result['err'])
else:
logger.debug('Successfully downloaded file with identifier %s', identifier)