def atomic_write(path):
tmp = tempfile.mktemp(
prefix='.' + os.path.basename(path),
dir=os.path.dirname(path),
)
try:
with open(tmp, 'w') as f:
yield f
except BaseException:
os.remove(tmp)
raise
else:
os.rename(tmp, path)
# TODO: at some point there will be so many options we'll want to make a config
# object or similar instead of adding more arguments here
评论列表
文章目录