kyl*_*lex 1 python interrupt-handling python-2.7
我有一个python脚本,可以创建大量的临时文件.如果脚本因ctrl + c中断而提前终止,我想在允许程序结束之前快速删除这些文件.
什么是pythonic方式处理这个?
use*_*ica 6
with如果可能,在语句中打开文件,或使用try带有finally关闭文件的块的语句.如果您正在使用tempfile,文件将在关闭时自动销毁; 否则,您可能需要在finally块中自行删除它们.
with
try
finally
tempfile
归档时间:
12 年,4 月 前
查看次数:
81 次
最近记录: