2014-10-31 626 views
0

這是我的代碼,當我運行它時,我得到第19行(for循環)的錯誤: TypeError:object'int'不可迭代。Python類型錯誤對象int不可迭代

import fb 
from facepy import GraphAPI 


token=""# access token here. 
facebook=fb.graph.api(token) 
graph1 = GraphAPI(token) 
vid="" #page id here 
query=str(vid)+"/feed" 
r=graph1.get(query) 
count=0 
nos=input("Enter number of posts: ") 
for indid in nos: 
     count=count+1 
    facebook.publish(cat="feed",id=indid,message="Hi"+str(count)) 
    time.sleep(6) 
    print("Wall post:"+str(count)) 

else : 
    print("No posts made.") 

請告訴我什麼是錯的。

+1

請做一些研究,這是一個非常基本的錯誤,只是簡單地用你的錯誤信息穀歌應該引導你許多SO問題相同的問題;例如https://stackoverflow.com/questions/19523563/python-typeerror-int-object-is-not-iterable或https://stackoverflow.com/questions/3887381/typeerror-nonetype-object-is-not-iterable- in-python或者https://stackoverflow.com/questions/18595695/python-typeerror-int-object-is-not-iterable et cetera。 – l4mpi 2014-10-31 07:39:23

回答

2

那麼,錯誤說明了一切:你嘗試在for循環這段代碼的迭代某int

nos=input("Enter number of posts: ") # nos is an int here 
for indid in nos: # and this is not how you iterate over an int 
     count=count+1 
    facebook.publish(cat="feed",id=indid,message="Hi"+str(count)) 

做出了一系列替代:

for count in range(0, nos): 
    facebook.publish(cat="feed",id=count,message="Hi"+str(count)) 

另外:我不不知道你想用indid做什麼。也許你還想問你要改變的postid ...

+0

'範圍(nos)'也適用 – Sayse 2014-10-31 07:47:20

相關問題