python tempfile创建文件

538次阅读
没有评论

python

python tempfile说明

python创建临时文件一般使用的模块就是tempfile。

python tempfile模块库函数

tempfile.mktemp  不安全,禁止使用

tempfile.mkstemp 随机创建tmp文件,默认创建的文件在/tmp目录

tempfile.TemporaryFile  内存中创建文件,文件不会存储在磁盘,关闭后即删除(可以使用)

python tempfile实例

fd, path = tempfile.mkstemp()try:    with os.fdopen(fd, 'w') as tmp:        # do stuff with temp file        tmp.write('stuff')finally:    os.remove(path)
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2021-04-24发表,共计352字。
新手QQ群:570568346,欢迎进群讨论 Python51学习