Latest web development tutorials

Python os.tmpfile () method

Python File (File) method Python OS file / directory methods


Outline

os.tmpfile () method returns an open mode (w + b) temporary file object, this object does not have a file folder entry, no file descriptor will be automatically deleted.

grammar

tmpfile () method syntax is as follows:

os.tmpfile

parameter

  • no

return value

Returns a temporary file object.

Examples

The following example demonstrates the use tmpfile () method:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os

# 创建临时文件对象
tmpfile = os.tmpfile()
tmpfile.write('临时文件在这创建了.....')
tmpfile.seek(0)

print tmpfile.read()
tmpfile.close

The above program output is:

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

Python File (File) method Python OS file / directory methods