1 回答

TA貢獻(xiàn)2041條經(jīng)驗 獲得超4個贊
您的方法似乎缺少縮進(jìn)tweet_photos。如果沒有這個縮進(jìn),解釋器將無法分辨方法的開始和結(jié)束位置。
此外,您正在嘗試迭代str. 在這種情況下, 的值x將是該字符串中的每個單獨字符。您可以通過在 Python 解釋器中運行以下代碼來驗證這一點:
imagePaths = "E:\Fotosprueba"
for x in imagePaths:
print(x)
輸出:
Python 3.6.1 (default, Dec 2015, 13:05:11)
[GCC 4.8.2] on linux
E
:
\
F
o
t
o
s
p
r
u
e
b
a
從表面上看,您可能希望將此 str 的值傳遞給該getPathsFromDir方法。嘗試這個:
def getPathsFromDir(dir, EXTS="extensions=,png,jpg,jpeg,gif,tif,tiff,tga,bmp"):
return this.listPaths(dir, EXTS) # This now uses the value of dir
def tweet_photos(api):
imagePaths = "E:\Fotosprueba"
# This now passes imagepaths to the getPathsFromDir method,
# and *should* return a list of files.
for x in getPathsFromDir(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
從理論上講,這應(yīng)該按預(yù)期工作,只要您的類還包含一個listPaths方法。如果沒有,您需要修改以包含此方法,或?qū)⒄{(diào)用更改this.listpaths為指向其他地方。
添加回答
舉報