tmpfile()方法返回以更新模式打開 (w+b) 新臨時檔的對象。該檔有沒有與之關聯的目錄項,當沒有檔描述符將被自動刪除。
語法
以下是 tmpfile() 方法的語法:
os.tmpfile
語法
-
NA
返回值
該方法返回一個新的臨時檔對象
示例
下麵的示例顯示 tmpfile() 方法的使用。
# !/usr/bin/python3 import os # The file has no directory entries associated with it and will be # deleted automatically once there are no file descriptors. tmpfile = os.tmpfile() tmpfile.write('Temporary newfile is here.....') tmpfile.seek(0) print tmpfile.read() tmpfile.close
當我們運行上面的程式,它會產生以下結果:
Temporary newfile is here.....
上一篇:
Python3檔方法
下一篇:
Python3 os檔目錄的方法