Python os.tmpfile() 方法
概述
os.tmpfile() 方法用于返回一個(gè)打開的模式為(w+b)的臨時(shí)文件對象,這文件對象沒有文件夾入口,沒有文件描述符,將會(huì)自動(dòng)刪除。
語法
tmpfile()方法語法格式如下:
os.tmpfile
參數(shù)
無
返回值
返回一個(gè)臨時(shí)文件對象。
實(shí)例
以下實(shí)例演示了 tmpfile() 方法的使用:
#!/usr/bin/python # -*- coding: UTF-8 -*- import os # 創(chuàng)建臨時(shí)文件對象 tmpfile = os.tmpfile() tmpfile.write('臨時(shí)文件在這創(chuàng)建了.....') tmpfile.seek(0) print tmpfile.read() tmpfile.close
執(zhí)行以上程序輸出結(jié)果為:
臨時(shí)文件在這創(chuàng)建了.....
更多建議: