我如何將此下載路徑添加到我tkinter使用 python 制作的GUI 應用程式中?
downloads_path = str(Path.home() / "Downloads")
對此
with open(f"{name}.mp4", "wb") as out:
out.write(video_bytes)
uj5u.com熱心網友回復:
由于您已經使用過pathlib.Pathclass,因此您可以保留downloads_pathas 型別pathlib.Path而不是string:
downloads_path = Path.home() / "Downloads"
然后你可以在第二個代碼塊中使用它,如下所示:
with open(downloads_path/f"{name}.mp4", "wb") as out:
out.write(video_bytes)
如果你仍然想保留downloads_path為字串,那么你可以使用os.path.join(...)如下:
import os
...
with open(os.path.join(downloads_path, f"{name}.mp4"), "wb") as out:
out.write(video_bytes)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/395485.html
上一篇:在等待json回應時未抓住承諾
