Python3 os.tmpfile()方法

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.....


上一篇: Python3文件方法 下一篇: Python3 os文件目录的方法