[臨時檔] 開啟臨時檔
##import##
import tempfile
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'
留言
張貼留言