2014-10-31 102 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

相关问题