Python编程:tempfile创建临时文件
2023-09-14 09:07:15 时间
tempfile需要的时候创建零时文件,关闭之后就被删除了
import tempfile
import os
# 创建文件
file = tempfile.TemporaryFile(mode="w+")
print(file.name)
# 4
print(os.path.exists(file.name))
# True
# 写入、读取操作
file.write("hello world")
file.seek(0)
print(file.read())
# hello world
# 关闭资源
file.close()
print(os.path.exists(file.name))
# False
相关文章
- seo与python大数据结合给文本分词并提取高频词
- Python编程之列表操作实例详解【创建、使用、更新、删除】
- python用reduce和map把字符串转为数字的方法
- python分段算利润、税收
- socket网络编程【python】
- Python网络编程之TCP套接字简单用法示例
- Python的组合模式与责任链模式编程示例
- Python编程之列表操作实例详解【创建、使用、更新、删除】
- 使用Python rembg库进行抠图:一行命令就搞定
- Python-GUI编程PyQT5案例:注册界面扇形菜单动画及相关事件处理
- 华为OD机试 - 优秀学员统计(Java & JS & Python)
- Python:Python语言编程软件安装的几大姿势之详细攻略
- mysql存储图片_Python
- 〖Python WEB 自动化测试实战篇⑨〗- 实战 - selenium 实现浏览器标签页的切换
- python 面向对象的概念及使用方法~(基础小知识)
- 【Python入门】NumPy 入门知识介绍,看这一篇足矣
- 【项目实战】Python基于KMeans算法进行文本聚类项目实战
- C++(Qt)与Python混合编程(一)
- Python编程:pandas入门
- Python编程:threading多线程之ThreadLocal
- Python编程:jupyter notebook安装启动
- Python编程:Python2编码问题与pymysql查询结果乱码解决
- Python编程:MySQLdb模块更新数据库获取影响行数
- Python编程:使用sqlalchemy对数据库进行增删改查
- python基础课程_学习笔记26:编程的乐趣
- python del语句作用在变量上,而不是数据对象(常量)上
- Python 并行编程
- Python模块资源仓库PyPI的使用教程