程序退出时删除临时文件,tempfile和atexit的结合应尽可能简单。
项目描述
tempfileatexit
Python库,用于程序结束时删除临时文件和目录。
安装
pip install tempfileatexit
用法
自动方式
import tempfileatexit as tfae
(fs, my_tempfile) = tfae.mkstemp()
my_tempdir = tfae.mkdtemp()
print(tempfileatexit.list(verbose=True))
手动方式
import tempfileatexit
import tempfile
(fs, my_tempfile) = tempfile.mkstemp()
my_tempdir = tempfile.mkdtemp()
tempfileatexit.register(my_tempfile)
tempfileatexit.register(my_tempdir)
print(tempfileatexit.list(verbose=True))
运行代码后程序存在,my_tempfile
和my_tempdir
将会消失。
项目详情
关闭
tempfileatexit-0.0.3.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | fc30db37a3a27f1cbab3469d4d286cf31a7f496039c495c1301789546a54fe32 |
|
MD5 | c8be9672e0487da58cf3d4ba322d3213 |
|
BLAKE2b-256 | 184d84c250a90c3ea9bdd293e98a8f1ece44b405efa2c25fbfe41df60480b2d7 |