金额= int(范围[1])的Python索引错误 - int(范围[0])

时间:2017-01-13 21:52:47

标签: python-3.x

我试图分割一系列数字,如1230-1236,因此每个数字都是单独命名的。

#if number is just a number write a name with that number
 if num.isdigit():
 photonum = str(num)
#add 0's to photo number until it is 4 digits long
 while len(photonum) < 4:
 photonum = "0"+photonum 
#write name using parts created 
 g.write(parts[0] + prefix +":"+ parts[1] +"_"+ parts[2] +"_"+ date +"_" + "(" + svf[0:5] + ")" + "_" +photonum+"\n")

#if number is a range, split it into two parts then write a name for every number between those parts                   
else:
range = num.split("-")
amount = int(range[1])-int(range[0])
c=0
while c<=amount:
photonum = str(int(range[0])+c)
while len(photonum) < 4:
photonum = "0"+photonum 
#write name using parts created 
g.write(parts[0] + prefix +":"+ parts[1] +"_"+ parts[2] +"_"+ date +"_" + "(" + svf[0:5] + ")" + "_" +photonum+"\n")
c+=1

我一直得到一个IndexError:列表索引超出此行的数量= int(range [1]) - int(range [0])

知道是什么导致了这个

0 个答案:

没有答案