你可以透過Python的os模組中的path.exists()方法來檢查檔案是否存在。如果檔案存在,可以使用datetime模組來生成一個新的檔案名稱。以下是示範程式碼
import os
from datetime import datetime
沒有痛苦 就沒有收穫
若內容對你有幫助,可以留言讓我知道哦~
有問題想要諮詢可以請至這裡連絡我哦 =>不會就放這邊
你可以透過Python的os模組中的path.exists()方法來檢查檔案是否存在。如果檔案存在,可以使用datetime模組來生成一個新的檔案名稱。以下是示範程式碼
import os
from datetime import datetime
hex_list = [f"{i:X}" for i in range(16)]
print(hex_list)
時間相減範例程式
start_dt = datetime.datetime.strptime(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), '%Y-%m-%d %H:%M:%S')
end_dt = datetime.datetime.strptime(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), '%Y-%m-%d %H:%M:%S')
每次都遇到 local variable referenced before assignment 錯誤的解決方案 這個問題
主要是變數需要變成全域變數才可以使用
可以參考這篇 : https://www.delftstack.com/zh-tw/howto/python/python-local-variable-referenced-before-assignment/