Python os.tmpfile() 方法

Python 教程 · 2019-02-04 12:56:55

概述

os.tmpfile() 方法用于返回一个打开的模式为(w+b)的临时文件对象,这文件对象没有文件夹入口,没有文件描述符,将会自动删除。

语法

tmpfile()方法语法格式如下:

os.tmpfile

参数

返回值

返回一个临时文件对象。

实例

以下实例演示了 tmpfile() 方法的使用:

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

import os

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

print tmpfile.read()
tmpfile.close

执行以上程序输出结果为:

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

点击查看所有 Python 教程 文章: https://codercto.com/courses/l/8.html

查看所有标签

The Probabilistic Method

The Probabilistic Method

Noga Alon、Joel H. Spencer / Wiley-Interscience / 2008-8-11 / USD 137.00

Praise for the Second Edition : "Serious researchers in combinatorics or algorithm design will wish to read the book in its entirety...the book may also be enjoyed on a lighter level since the diffe......一起来看看 《The Probabilistic Method》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

在线进制转换器
在线进制转换器

各进制数互转换器

URL 编码/解码
URL 编码/解码

URL 编码/解码