2013-02-25 87 views
0

下面是一些代碼,我已經寫了:IndexError:列表索引超出範圍蟒蛇

class MyClass: 
    listt=[] 
    def __init__(self): 
     "" 

instancelist = [ MyClass() for i in range(29)] 
for i in range(0,29): 
    instancelist[i].listt[i].append("ajay") 
print instancelist 

我收到此錯誤:

File "/home/aj/workspace/PythonTutorials/basics/builtFun.py", line 16, in <module> 
    instancelist[i].listt[i].append("ajaajayy") 
IndexError: list index out of range 

我怎樣才能解決這個問題?

+0

什麼是編輯? – 2013-02-25 05:01:32

+0

爲什麼你要創建一個只包含'list'實例的類? – Johnsyweb 2013-02-25 05:44:02

回答

1
class MyClass: 
    listt=[] 
    def __init__(self): 
     "" 

instancelist = [ MyClass() for i in range(29)] 
for i in range(0,29): 
    instancelist[i].listt.append("ajay") 
print instancelist 

固定。