你可以透過Python的os模組中的path.exists()方法來檢查檔案是否存在。如果檔案存在,可以使用datetime模組來生成一個新的檔案名稱。以下是示範程式碼
import os
from datetime import datetime
JL8051 發表在 痞客邦 留言(0) 人氣(8)
hex_list = [f"{i:X}" for i in range(16)]
print(hex_list)
JL8051 發表在 痞客邦 留言(0) 人氣(6)
Python use
strhex = "0x01"
int(strhex,16)
JL8051 發表在 痞客邦 留言(0) 人氣(4)

時間相減範例程式
start_dt = datetime.datetime.strptime(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), '%Y-%m-%d %H:%M:%S')
JL8051 發表在 痞客邦 留言(0) 人氣(73)
每次都遇到 local variable referenced before assignment 錯誤的解決方案 這個問題
主要是變數需要變成全域變數才可以使用
JL8051 發表在 痞客邦 留言(0) 人氣(977)
進入pyhton
>>> int("0x12F", base=16)
303
JL8051 發表在 痞客邦 留言(0) 人氣(22)

python太多語法,放這邊練習
filedialog 對話框函數測試
import tkinter as tk
from tkinter import ttk
from tkinter import filedialog as fd
def do_askopenfilename():
file=fd.askopenfilename()
print(type(file))
print(file)
def do_askopenfilenames():
files=fd.askopenfilenames()
print(type(files))
print(files)
def do_asksaveasfilename():
file=fd.asksaveasfilename()
print(type(file))
print(file)
def do_askdirectory():
dir=fd.askdirectory()
print(type(dir))
print(dir)
def do_askopenfile():
file=fd.askopenfile()
print(type(file))
print(file)
def do_askopenfiles():
files=fd.askopenfiles()
print(type(files))
print(files)
def do_asksaveasfile():
file=fd.asksaveasfile()
print(type(file))
print(file)
root=tk.Tk()
root.title("檔案開啟儲存")
ttk.Button(root, text="askopenfilename", command=do_askopenfilename).pack()
ttk.Button(root, text="askopenfilenames", command=do_askopenfilenames).pack()
ttk.Button(root, text="asksaveasfilename", command=do_asksaveasfilename).pack()
ttk.Button(root, text="askdirectory", command=do_askdirectory).pack()
ttk.Button(root, text="askopenfile", command=do_askopenfile).pack()
ttk.Button(root, text="askopenfiles", command=do_askopenfiles).pack()
ttk.Button(root, text="asksaveasfile", command=do_asksaveasfile).pack()
root.mainloop()
JL8051 發表在 痞客邦 留言(0) 人氣(152)
更新: 原來是我read回來最後一個字串帶有換行
所以當我在寫入時,就會有多一個換行的\n寫入
JL8051 發表在 痞客邦 留言(0) 人氣(77)
使用python 上傳資料到google excel上
https://sites.google.com/site/zsgititit/home/python-cheng-shi-she-ji/shi-yongpython-shang-chuan-zi-liao-daogoogle-shi-suan-biao
JL8051 發表在 痞客邦 留言(1) 人氣(39)
錯誤:UnboundLocalError: local variable 'aww' referenced before assignment
原因 : 變數沒有設定global
JL8051 發表在 痞客邦 留言(0) 人氣(16)