描述
方法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.....
相關用法
- Python 3 os.tmpnam()用法及代碼示例
- Python 3 os.tcgetpgrp()用法及代碼示例
- Python 3 os.tcsetpgrp()用法及代碼示例
- Python 3 os.tempnam()用法及代碼示例
- Python 3 os.ttyname()用法及代碼示例
- Python 3 os.fstatvfs()用法及代碼示例
- Python 3 os.minor()用法及代碼示例
- Python 3 os.close()用法及代碼示例
- Python 3 os.unlink()用法及代碼示例
- Python 3 os.major()用法及代碼示例
- Python 3 os.rmdir()用法及代碼示例
- Python 3 os.fdopen()用法及代碼示例
- Python 3 os.fdatasync()用法及代碼示例
- Python 3 os.isatty()用法及代碼示例
- Python 3 os.rename()用法及代碼示例
- Python 3 os.walk()用法及代碼示例
- Python 3 os.renames()用法及代碼示例
- Python 3 os.makedirs()用法及代碼示例
- Python 3 os.utime()用法及代碼示例
- Python 3 os.statvfs()用法及代碼示例
注:本文由純淨天空篩選整理自 Python 3 - os.tmpfile() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。