首页 > 编程语言 > 详细

Python模块学习——tempfile

时间:2014-01-24 05:26:41      阅读:423      评论:0      收藏:0      [点我收藏+]

主要有以下几个函数:

tempfile.TemporaryFile

如何你的应用程序需要一个临时文件来存储数据,但不需要同其他程序共享,那么用TemporaryFile函数创建临时文件是最好的选择。其他的应用程序是无法找到或打开这个文件的,因为它并没有引用文件系统表。用这个函数创建的临时文件,关闭后会自动删除。


bubuko.com,布布扣
 1 import os
 2 import tempfile
 3  
 4 print Building a file name yourself:
 5 filename = /tmp/guess_my_name.%s.txt % os.getpid()
 6 temp = open(filename, w+b)
 7 try:
 8     print temp:, temp
 9     print temp.name:, temp.name
10 finally:
11     temp.close()
12     os.remove(filename)     # Clean up the temporary file yourself
13  
14 print
15 print TemporaryFile:
16 temp = tempfile.TemporaryFile()
17 try:
18     print temp:, temp
19     print temp.name:, temp.name
20 finally:
21     temp.close()  # Automatically cleans up the file
bubuko.com,布布扣

Python模块学习——tempfile

原文:http://www.cnblogs.com/juxuan/p/3531577.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!