【问题标题】:Python- TypeError object int is not iterable [duplicate]Python- TypeError 对象 int 不可迭代 [重复]
【发布时间】:2014-10-31 15:41:33
【问题描述】:

这是我的代码,当我运行它时,第 19 行出现错误(for 循环): 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.")

请告诉我有什么问题。

【问题讨论】:

标签: python typeerror


【解决方案1】:

好吧,错误说明了一切:您尝试在此代码的 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...

【讨论】:

  • range(nos) 也同样有效
猜你喜欢
  • 2015-04-06
  • 2013-10-31
  • 2016-02-24
  • 1970-01-01
  • 2017-09-11
  • 1970-01-01
  • 2023-01-22
相关资源
最近更新 更多