![](/img/trans.png)
[英]Saving file with a name containing / at the destination folder in python
[英]Saving image of every python execution in a folder with a serial number as file name
我是 Python 的初學者,想執行一個將圖像保存到特定目錄的代碼。 問題是,我想用序列號保存圖像,這樣我就可以在目錄中有很多圖像(每次執行都會給出一個圖像)。
plt.savefig('Images/Imageplot.png') ## Image saved to particular folder
關於序列號,您可以使用 uuid 庫為圖像生成一個隨機且唯一的 id。 在此處查看更多信息: https ://www.geeksforgeeks.org/generating-random-ids-using-uuid-python/
要保存圖像,它有點復雜。 它要求您導入 os 庫。
這是一個例子:
import os
UPLOADED_FILE_DIR_PATH = os.path.join(os.path.dirname(__file__), "static", "uploaded-images")
my_file_path = os.path.join(UPLOADED_FILE_DIR_PATH, my_filename)
image_file.save(my_file_path)
這是我以前用於我的網站的代碼塊,因此它可能不適用於您,具體取決於您的情況。 我個人喜歡這種方法,但如果您不滿意,請查看此方法以獲取更多選項: https ://towardsdatascience.com/loading-and-saving-images-in-python-ba5a1f5058fb
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.