Python-TypeError 对象 int 不可迭代 [英] Python- TypeError object int is not iterable
本文介绍了Python-TypeError 对象 int 不可迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码,当我运行它时,我在第 19 行(for 循环)出现错误:类型错误:对象int"不可迭代.
Here is my code, when I am running it I get error on line 19 (for loop): TypeError: object 'int' is not iterable.
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.")
请告诉我怎么了.
推荐答案
好吧,错误说明了一切:您尝试迭代 for
循环中的 int
这段代码:
Well, the error says it all: you try to iterate over an int
in the for
loop of this code:
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...
furthermore: I don't know what you try to do with indid
. Maybe you also want to ask for the postid you want to change...
这篇关于Python-TypeError 对象 int 不可迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文