[臨時檔] 開啟臨時檔

##import##
import tempfile

##generate temporary file and write##
with tempfile.NamedTemporaryFile(suffix='.txt', prefix='tmp',
  dir='d:\\cykuo\\tmp'delete=False) as f:
    print(f.name)
    f.write(b'test data')
    #若沒有加b, 會出現 Excption:
    # TypeError: a bytes-like object is required, not 'str'

留言

這個網誌中的熱門文章

[環境設定] 應用程式執行別名

[變數] 使用全域變數