Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python os.tmpfile() method

Python os.tmpfile() method

Python File methods Python OS file/directory methods


Overview

The os.tmpfile() method returns a temporary file object opened in mode (w+b). This file object has no folder entry, no file descriptor, and will be deleted automatically.

Syntax

The syntax of the **tmpfile()** method is as follows:


os.tmpfile

Parameters

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

# Create temporary file object
tmpfile = os.tmpfile()
tmpfile.write('临时文件在这创建了.....')
tmpfile.seek(0)

print tmpfile.read()
tmpfile.close

The output of the above program is:


临时文件在这创建了.....

Python File methods Python OS file/directory methods