python 递减的for循环_在递增for循环中递减变量

在我的python脚本中,我从索引9开始遍历一个列表(headerRow)。我想检查它是否已经在数据库中,如果不在,则将其添加到具有自动激励主键的数据库中。然

在我的python脚本中,我从索引9开始遍历一个列表(headerRow)。我想检查它是否已经在数据库中,如果不在,则将其添加到具有自动激励主键的数据库中。然后我想再次通过循环发送它来检索它的主键。for i in range (9, len(headerRow)):

# Attempt to retrieve an entry's corresponding primary key.

row = cursor.fetchone()

print i

if row == None: # New Entry

# Add entry to database

print "New Entry Added!"

i -= 1 # This was done so that it reiterates through and can get the PK next time.

print i

else: # Entry already exists

print "Existing Entry"

qpID = row[0]

# ...

以下是我的脚本输出:9

New Question Added!

8

10

New Question Added!

9

11

如您所见,我的问题是range()不关心i的现有值是什么。做我想做的事情,python的首选方法是什么?

提前谢谢你

迈克