所以我不知道我的确切问题是什么,我是一个业余程序员,所以我不完全知道我做的是对的还是错的。所以如果有人能帮我一点忙,我会非常感激的。 这是我的代码,我真的不知道我在失败什么,因为它说这是一个失败的路径:
import tweepy
from time import sleep
folderpath= "E:\Fotosprueba"
def tweepy_creds():
consumer_key = 'x'
consumer_secret = 'x'
access_token = 'x'
access_token_secret = 'x'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
return tweepy.API(auth)
def getPathsFromDir(dir, EXTS="extensions=,png,jpg,jpeg,gif,tif,tiff,tga,bmp"):
return this.listPaths('E:\Fotosprueba', EXTS)
def tweet_photos(api):
imagePaths = "E:\Fotosprueba"
for x in imagePaths:
status = "eeeee macarena"
try:
api.update_with_media(filename=x,status=status)
print ("Tweeted!")
sleep(10)
except Exception as e:
print ("encountered error! error deets: %s"%str(e))
break
if __name__ == "__main__":
tweet_photos(tweepy_creds())
您的
tweet_photos
方法似乎缺少缩进。如果没有这个缩进,解释器将无法判断方法的开始和结束位置此外,您还试图迭代
str
。在本例中,x
的值将是该字符串中的每个单独字符。您可以通过在Python解释器中运行以下代码来验证这一点:输出:
从外观上看,您可能希望将这个str的值传递给
getPathsFromDir
方法。试试这个:从理论上讲,只要类还包含
listPaths
方法,就可以按预期工作。如果没有,则需要修改以包含此方法,或者更改对this.listpaths
的调用以指向其他地方相关问题 更多 >
编程相关推荐