2016-02-26 92 views
0

在Google上對此錯誤或StackOverflow沒有任何結果。TypeError:'PosixPath'對象不支持索引

我讀到pathlib是處理路徑的新Python方式。

所以我做的:

with open(pic_name, 'wb') as image: 
       image.write(download.content) 
       image_path = Path(pic_name).resolve() 
       return image_path 

當我打印image_path我得到的完整路徑的形象,但是當我試圖把它傳遞到使用的ffmpeg創建視頻文件的功能,我得到:

TypeError: Can't convert 'PosixPath' object to str implicitly

我懷疑這是因爲對象是POSIX和ffmpeg的shell命令期望一個字符串,但你如何變換一個POSIX路徑的字符串?

回答

0

Python不能做到這一點含蓄,但你可以明確地做到這一點:

str(image_path)