Python os.tmpfile() Method
Python OS File/Directory Methods
Overview
The os.tmpfile() method is used to return a temporary file object opened in (w+b) mode. This file object has no folder entry, no file descriptor, and will be automatically deleted.
Syntax
tmpfile()The method syntax is as follows:
os.tmpfile
Parameters
None
Return Value
Returns a temporary file object.
Example
The following example demonstrates the use of the tmpfile() method:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
# 创建临时文件对象
tmpfile = os.tmpfile()
tmpfile.write('临时文件在这创建了.....')
tmpfile.seek(0)
print tmpfile.read()
tmpfile.close
The output after executing the above program is:
The temporary file was created here.....Other Extensions