Python coding - list index out of range -


lots of code here

...

if c==excelfiles[1]:     b ==excelfiles[1]     wb = xlrd.open_workbook(a)     wb.sheet_names()     sh = wb.sheet_by_index(0)     rownum in range(sh.nrows):         print sh.row_values(rownum)  in range(sheet.nrows):     cashflow = [sheet.cell_value(i,0)],[sheet.cell_value(i,1)],[sheet.cell_value(i,2)]     print cashflow  def npv(rate, cashflow):     value = cashflow[1] * ((1 + rate/100) ** (12 - cashflow[0]))     fv = 0     fv += value     return fv  def irr(cashflow, iterations = 100):     rate = 1.0      = 0     while (cashflow[0][1] == 0):         += 1      investment = cashflow[i][1]      in range(1, iterations+1):         rate *= (1 - (npv(rate, cashflow) / investment))         return rate  r = irr(cashflow)  print r 

error/output:

  file "<pyshell#90>", line 1, in <module>     import quarterz   file "quarterz.py", line 65, in <module>     r = irr(cashflow) # why list index out of range?   file "quarterz.py", line 56, in irr     while (cashflow[0][1] == 0): indexerror: list index out of range 

can please explain why list index out of range? , can show me how fix this? relatively new python i'm sure it's stupid mistake.

thanks much!

i've attached code here: http://ideone.com/g5hguk

cashflow[0] set [sheet.cell_value(i,0)] in loop on line 10, list length 1. expression cashflow[0][1] trying read second value in list.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -