2017-02-20 81 views
0

我有以下代碼。每次我運行此我得到的錯誤TypeError:'int'object is not iterble

TypeError: 'int' object is not iterable for the 'Number'.

f = open("E:\\vivek.txt","r") 
waitstate = 0 
Number = [] 
l_ines = [] 
l_ines=f.readlines() 
#print(l_ines) 
for i in l_ines: 
    if len(i.split("# Waits"))>1: 
     elements = [] 
     elements = ((i.split("# Waits")[1]).split(" ")) 
     for j in elements: 
      if j!="": 
       try:      
        Number = (int (j)) 
        #Number = j 
        #print(Number) 
       except: 
         pass 
for i in Number: 
    print(i) 
+0

'對於我在Number:','Number'是'int'。你可能想'append'而不是set('=')'Number' ... –

+0

將Number =(int(j))更改爲'Number.append(int(j))' –

+0

No change Number =(int(j))''Number.append(int(j))'... –

回答

0

更換

Number = (int (j)) 

隨着

Number.append(int(j)) 

因爲你已經定義號碼作爲列表,你不能再改變它爲一個整數,你需要將整數附加到列表中。

+0

非常感謝。有用。 – vivek

+0

不用擔心,很高興它解決了:) – ocelot