Python os.tmpfile() 方法



Python 方法tmpfile() 返回一個以更新模式 (w+b) 開啟的新臨時檔案物件。該檔案沒有與其關聯的目錄條目,並且一旦沒有檔案描述符,它將被自動刪除。

Python os.tmpfile() 方法已棄用。

語法

以下是 Python os.tmpfile() 方法的語法:

os.tmpfile()

引數

Python os.tmpfile() 方法不接受任何引數。

返回值

Python os.tmpfile() 方法返回一個新的臨時檔案物件

示例

以下示例顯示了 tmpfile() 方法的用法。

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_files_io.htm
廣告

© . All rights reserved.